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
- module Data.Time
- herfShow :: (HerfedTime t, FormatTime t) => t -> String
- reherf :: (ToUTCHerfTime a, ToUTCHerfTime b, FromUTCHerfTime a, FromUTCHerfTime b) => a -> b
- 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
- data UTCHerfTime
- 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 ToUTCHerfTime a where
- herf :: a -> UTCHerfTime
- class FromUTCHerfTime a where
- unherf :: UTCHerfTime -> a
- class HerfAdd a where
- add :: HerfedTime t => t -> a -> t
- data HerfYear
- data HerfMonth
- data HerfWeek
- data HerfDay
- data HerfHour
- data HerfMin
- data HerfSec
- data HerfPico
- year :: Integer -> HerfYear
- month :: Integer -> HerfMonth
- week :: Integer -> HerfWeek
- day :: Integer -> HerfDay
- hour :: Integer -> HerfHour
- minute :: Integer -> HerfMin
- second :: Integer -> HerfSec
- pico :: Integer -> HerfPico
Documentation
module Data.Time
herfShow :: (HerfedTime t, FormatTime t) => t -> String Source
Display herf times in a pre formatted way
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))
getSeconds :: UTCTime -> Integer Source
getSeconds someUtcTime -> 1s
getPicoseconds :: UTCTime -> Integer Source
getPicoseconds somUTCTime -> 1ps
data 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, 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 | |
KnownSymbol z => HerfedTime (HerfZonedTime z) Source |
|
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 |
KnownSymbol z => ToUTCHerfTime (HerfZonedTime z) Source |
class FromUTCHerfTime a where Source
come back from the UTCHerfTime universal represenation
unherf :: UTCHerfTime -> a Source
This provides the unified interface to herfed times. All instances of this class should obey the rule that if some interval you are adding is equivalent in another HerfAdd time then there should be no difference between adding that many to a HerfedTime i.e. (HerfMin 1) == (HerfSec 60) (herf $ add someTime (HerfMin 1) ) == (herf $ add someTime (HerfMin 60))
add :: HerfedTime t => t -> a -> t Source
Simple representation of a time interval of a year
Simple representation of a time interval of a month
Simple representation of a time interval of a week
Simple representation of a time interval of a day
Simple representation of a time interval of a hour
Simple representation of a time interval of a minute
Simple representation of a time interval of a second
Simple representation of a time interval of a picosecond
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
Interface functions following Kerf y