Safe Haskell | None |
---|---|
Language | Haskell2010 |
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
- year :: Integer -> HerfYear
- month :: Integer -> HerfMonth
- week :: Integer -> HerfWeek
- day :: Integer -> HerfDay
- hour :: Integer -> HerfHour
- minute :: Integer -> HerfMin
- second :: Integer -> HerfSec
- pico :: Integer -> HerfPico
- herfShow :: FormatTime t => t -> String
- dateHerf :: Integer -> Integer -> Integer -> UTCHerfTime
- time :: Integer -> Integer -> Integer -> DiffTime
- timePico :: Integer -> Integer -> Integer -> Integer -> DiffTime
- dateTimeHerf :: Integer -> Integer -> Integer -> Integer -> Integer -> Integer -> UTCHerfTime
- dateTimePicoHerf :: Integer -> Integer -> Integer -> Integer -> Integer -> Integer -> Integer -> UTCHerfTime
- newtype UTCHerfTime = UTCHerfTime UTCTime
- class ToUTCHerfTime a where
- herf :: a -> UTCHerfTime
- class FromUTCHerfTime a where
- unherf :: UTCHerfTime -> a
- reherf :: (ToUTCHerfTime a, ToUTCHerfTime b, FromUTCHerfTime a, FromUTCHerfTime b) => a -> b
- class (ToUTCHerfTime a, FromUTCHerfTime a) => HerfedTime a where
- addYear :: a -> HerfYear -> a
- addMonth :: a -> HerfMonth -> a
- addWeek :: a -> HerfWeek -> a
- addDay :: a -> HerfDay -> a
- addHour :: a -> HerfHour -> a
- addMinute :: a -> HerfMin -> a
- addSecond :: a -> HerfSec -> a
- addPicosecond :: a -> HerfPico -> a
- date :: HerfYear -> HerfMonth -> HerfDay -> a
- dateTime :: HerfYear -> HerfMonth -> HerfDay -> HerfHour -> HerfMin -> HerfSec -> a
- dateTimePico :: HerfYear -> HerfMonth -> HerfDay -> HerfHour -> HerfMin -> HerfSec -> HerfPico -> a
- class HerfAdd a where
- add :: HerfedTime t => t -> a -> t
- newtype HerfYear = HerfYear Integer
- newtype HerfMonth = HerfMonth Integer
- newtype HerfWeek = HerfWeek Integer
- newtype HerfDay = HerfDay Integer
- newtype HerfMin = HerfMin Integer
- newtype HerfHour = HerfHour Integer
- newtype HerfSec = HerfSec Integer
- newtype HerfPico = HerfPico Integer
- getYear :: UTCTime -> Integer
- getMonth :: UTCTime -> Integer
- getDay :: UTCTime -> Integer
- getDateParts :: UTCTime -> (Integer, Integer, Integer)
- getHour :: UTCTime -> Integer
- getMin :: UTCTime -> Integer
- getSeconds :: UTCTime -> Integer
- getPicoseconds :: UTCTime -> Integer
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
herfShow :: FormatTime t => t -> String Source
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
dateTimeHerf :: Integer -> Integer -> Integer -> Integer -> Integer -> Integer -> UTCHerfTime Source
dateTimePicoHerf :: Integer -> Integer -> Integer -> Integer -> Integer -> Integer -> Integer -> UTCHerfTime Source
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
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
herf :: a -> UTCHerfTime Source
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 |
class FromUTCHerfTime a where Source
unherf :: UTCHerfTime -> a 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
addYear :: a -> HerfYear -> a Source
addMonth :: a -> HerfMonth -> a Source
addWeek :: a -> HerfWeek -> a Source
addDay :: a -> HerfDay -> a Source
addHour :: a -> HerfHour -> a Source
addMinute :: a -> HerfMin -> a Source
addSecond :: a -> HerfSec -> a Source
addPicosecond :: a -> HerfPico -> a Source
date :: HerfYear -> HerfMonth -> HerfDay -> a Source
dateTime :: HerfYear -> HerfMonth -> HerfDay -> HerfHour -> HerfMin -> HerfSec -> a Source
dateTimePico :: HerfYear -> HerfMonth -> HerfDay -> HerfHour -> HerfMin -> HerfSec -> HerfPico -> a Source
HerfedTime UTCTime Source | Get Times in any viable format (UTC for example)
>>> unherf $ date 2016 01 01 |
HerfedTime UTCHerfTime Source |
add :: HerfedTime t => t -> a -> t Source
getSeconds :: UTCTime -> Integer Source
getSeconds someUtcTime -> 1s
getPicoseconds :: UTCTime -> Integer Source