MyNixOS website logo
Description

haskell time manipulation in a 'kerf like' style.

The herf-time package attempts to make the time package's syntax more straightforward for doing interval math and conversion. It borrows heavily from the syntax of the kerf programming language https://github.com/kevinlawler/kerf . But unlike kerf, there are no promisses of high performance code here. The performance seems adequate for lots of uses though and manipulating time in the herf library is pretty fun.

The KerfTime module is self contained and the only dependency is the time package.

Add intervals of varying amounts.

date 2016 01 01 `add` hour 3 `add` week 16 `add` month 3 :: UTCHerfTime

UTCHerfTime 2016-07-22 03:00:00 UTC

Subtract intervals as well

date 2016 01 01 `add` hour (-3) `add` week (-16) `add` month (-3) :: UTCHerfTime

UTCHerfTime 2015-06-10 21:00:00 UTC

Use the same interval notation for different time representation

dateTime 2016 01 01 01 23 01 `add` (hour 3) `add` (week 16) `add` (month 3) :: UTCHerfTime

UTCHerfTime 2016-07-22 04:23:01 UTC

(reherf $ ( dateTime 2016 01 01 01 01 01 :: HerfZonedTime "CST")) :: HerfZonedTime "PST"

2015-12-31T23:01:01:PST

zt <- getZonedTime
herfShow zt

"2016-01-21T11:29:05:CST"

reherfz zt :: HerfZonedTime "PST"

2016-01-21T09:29:05:PST

reherfz zt :: HerfZonedTime "+0600"

2016-01-21T23:29:05:+0600

reherfz zt :: HerfZonedTime "CST"

2016-01-21T11:29:05:CST

(reherfz zt) `add` month 2 :: HerfZonedTime "CST"

2016-03-21T11:29:05:CST

(reherfz zt) `add` month 2 :: HerfZonedTime "PST"

2016-03-21T09:29:05:PST

herf-time

Circle CI

Haskell's time library is nice but I wanted to be able to do some of the operations in the Kerf programming language.

By creating a set of type classes: HerfedTime , ToUTCHerfTime, FromUTCHerfTime I think there is a nice mechanism to do just that.

any instance of these 3 classes should satisfy the law:

  • Path Independant on all addtion
  • addX a X == unherf (addX (herf a) X )
    • where: addX := {addYear , addMonth, addWeek ...}

Tutorial

Herf Tutorial

Usage

Add Intervals

>>> date 2016 01 01 `add` hour 3 `add` week 16 `add` month 3 :: UTCTime
UTCHerfTime 2016-07-22 03:00:00 UTC

Subtract Intervals


>>> date 2016 01 01 `add` hour (-3) `add` week (-16) `add` month (-3) :: UTCTime
UTCHerfTime 2015-06-10 21:00:00 UTC

Represent Time in Multiple Ways


>>> dateTime 2016 01 01 01 23 01 `add` hour 3 `add` week 16 `add` month 3 :: UTCTime
UTCHerfTime 2016-07-22 04:23:01 UTC
>>> dateTimePico 2016 01 01 01 23 01 01 `add` hour 3 `add` week 16 `add` month 3 :: UTCTime
UTCHerfTime 2016-07-22 04:23:01.000000000001 UTC

Get Times in any HerfedTime format (UTC for example)

>>> date 2016 01 01 `add` hour 3 `add` week 16 `add` month 3   :: UTCTime
2016-07-22 03:00:00 UTC

Use HerfTime.ZonedTime to convert easily between times

(reherf $ ( dateTime 2016 01 01 01 01 01 :: HerfZonedTime "CST")) :: HerfZonedTime "PST" 2015-12-31T23:01:01:PST

Some fancier examples (Using HerfTime.ZonedTime)

λ> zt <- getZonedTime
λ> herfShow zt
"2016-01-21T11:29:05:CST"
λ> reherfz zt :: HerfZonedTime "PST"
2016-01-21T09:29:05:PST
λ> reherfz zt :: HerfZonedTime "+0600"
2016-01-21T23:29:05:+0600
λ> reherfz zt :: HerfZonedTime "CST"
2016-01-21T11:29:05:CST
λ> (reherfz zt) `add` month 2 :: HerfZonedTime "CST"
2016-03-21T11:29:05:CST

-- What time will it be exactly 3 months from now in California?
λ> (reherfz zt) `add` month 2 :: HerfZonedTime "PST"
2016-03-21T09:29:05:PST
cabal configure --enable-tests && cabal build && cabal test
Metadata

Version

0.3.1

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows