herf-time-0.1.0: haskell time manipulation in a 'kerf like' style.

Safe HaskellNone
LanguageHaskell2010

HerfTime

Description

The Herf Time package is loosely based on the Kerf programming language's approach to time. https://github.com/kevinlawler/kerf

Where it made sense to do things differently it does.

The fundamental engine is the typeclass HerfTime

Synopsis

Documentation

year :: Integer -> HerfYear Source

Add Intervals of different amounts

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

Represent Time in a few different ways

>>> 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
>>> dateTimePico 2016 01 01 01 23 01 01 `add` (hour 3) `add` (week 16) `add` (month 3) :: UTCHerfTime
UTCHerfTime 2016-07-22 04:23:01.000000000001 UTC

Use negative signs to subtract

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

dateHerf :: Integer -> Integer -> Integer -> UTCHerfTime Source

>>> date 1 1 1 :: UTCHerfTime
UTCHerfTime 0001-01-01 00:00:00 UTC

time :: Integer -> Integer -> Integer -> DiffTime Source

Time only, you can't just add a diff time to a date so we get a diff time back >>> time 1 1 1 3661s

newtype UTCHerfTime Source

Below are the classes that make up the core of the HerfTime Library. Starting with the type UTCHerfTime which is the encoding that most other time stamps pass through

Constructors

UTCHerfTime UTCTime 

class ToUTCHerfTime a where Source

The ToUTCHerfTime is necessary to have an interface lifted so that all the functions can be abstracted over it

Methods

herf :: a -> UTCHerfTime Source

Instances

ToUTCHerfTime UTCTime Source

UTCTime is the underlying and most important HerfTime thing

ToUTCHerfTime UTCHerfTime Source

NominalHerf time will obey the laws of HerfedTime by default

reherf :: (ToUTCHerfTime a, ToUTCHerfTime b, FromUTCHerfTime a, FromUTCHerfTime b) => a -> b Source

reherf is not part of a typeclass, just more sugar to make dealing with time conversion If both classes are defined on the same type, the classes should round trip. e.g. (date y m d ):: UTCTime in d == (reherf d))

class (ToUTCHerfTime a, FromUTCHerfTime a) => HerfedTime a where Source

This defines the time language of herf the important rule here is path independence (unherf $ (herf a) add i ) == (a add i)

This ensures that regardless of how you get to a time the result will be the same

Something to notice is that rule still allows for lossy Time Stamps. The loss just has to be captured uniformally in the transforms and the interval arithmetic

Instances

HerfedTime UTCTime Source

Get Times in any viable format (UTC for example) >>> unherf $ date 2016 01 01 add hour 3 add week 16 add month 3 :: UTCTime 2016-07-22 03:00:00 UTC

HerfedTime UTCHerfTime Source 

getYear :: UTCTime -> Integer Source

getYear someUtcTime -> 2016y

getMonth :: UTCTime -> Integer Source

getMonth someUtcTime -> 10m

getDay :: UTCTime -> Integer Source

getDay someUtcTime -> 31d

getDateParts :: UTCTime -> (Integer, Integer, Integer) Source

Get all date parts together

getHour :: UTCTime -> Integer Source

getHour someUtcTime -> 1h

getMin :: UTCTime -> Integer Source

getMin someUtcTime -> 37i

getSeconds :: UTCTime -> Integer Source

getSeconds someUtcTime -> 1s