herf-time-0.2.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 

Instances

Eq UTCHerfTime Source # 
Ord UTCHerfTime Source # 
Show UTCHerfTime Source # 
FormatTime UTCHerfTime Source # 
HerfedTime UTCHerfTime Source # 
FromUTCHerfTime UTCHerfTime Source # 
ToUTCHerfTime UTCHerfTime Source #

NominalHerf time will obey the laws of HerfedTime by default

class ToUTCHerfTime a where Source #

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

Minimal complete definition

herf

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

KnownSymbol z => ToUTCHerfTime (HerfZonedTime z) Source # 

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 # 
KnownSymbol z => HerfedTime (HerfZonedTime z) Source #
>>> :set -XDataKinds
>>> (reherf $ ( dateTime 2016 01 01 01 01 01 :: HerfZonedTime "CST")) :: HerfZonedTime "PST"
2015-12-31T23:01:01:PST

class HerfAdd a where Source #

Minimal complete definition

add

Methods

add :: HerfedTime t => t -> a -> t Source #

Instances

HerfAdd HerfPico Source # 

Methods

add :: HerfedTime t => t -> HerfPico -> t Source #

HerfAdd HerfSec Source # 

Methods

add :: HerfedTime t => t -> HerfSec -> t Source #

HerfAdd HerfHour Source # 

Methods

add :: HerfedTime t => t -> HerfHour -> t Source #

HerfAdd HerfMin Source # 

Methods

add :: HerfedTime t => t -> HerfMin -> t Source #

HerfAdd HerfDay Source # 

Methods

add :: HerfedTime t => t -> HerfDay -> t Source #

HerfAdd HerfWeek Source # 

Methods

add :: HerfedTime t => t -> HerfWeek -> t Source #

HerfAdd HerfMonth Source # 

Methods

add :: HerfedTime t => t -> HerfMonth -> t Source #

HerfAdd HerfYear Source # 

Methods

add :: HerfedTime t => t -> HerfYear -> t 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