| Safe Haskell | Safe-Infered |
|---|
Data.Time.Lens
- class HasTime a where
- hours :: HasTime a => Lens a Int
- minutes :: HasTime a => Lens a Int
- seconds :: HasTime a => Lens a Pico
- class HasDate a where
- year :: HasDate a => Lens a Integer
- month :: HasDate a => Lens a Int
- day :: HasDate a => Lens a Int
- gregorian :: HasDate a => Lens a (Integer, Int, Int)
- class HasTime a => HasTimeZone a where
- data Day
- data TimeOfDay
- data LocalTime
- data ZonedTime
- getZonedTime :: IO ZonedTime
- data Lens a b
- getL :: Lens a b -> a -> b
- modL :: Lens a b -> (b -> b) -> a -> a
- setL :: Lens a b -> b -> a -> a
Time
The semantics of getL for time lenses (time,hours,minutes,seconds)
is straightforward.
The semantics of setL is to «normalize» the time before setting. Hence
will correctly add 5 minutes to the time, e.g.
modL minutes (+5)
>>>modL minutes (+5) (TimeOfDay 16 57 13)17:02:13
If this means crossing a day boundary, the semantics varies for different
structures. For structures that have a date component (i.e. for instances of
HasDate) the date is adjusted appropriately.
>>>modL hours (+10) (LocalTime (fromGregorian 2012 05 23) (TimeOfDay 16 57 13))2012-05-24 02:57:13>>>modL seconds (subtract 1) (LocalTime (fromGregorian 2012 05 23) (TimeOfDay 0 0 0))2012-05-22 23:59:59
If there's no date, the time is simply wrapped around.
>>>modL seconds (subtract 1) (TimeOfDay 0 0 0)23:59:59
Date
In contrast to time, the date lens is a simple accessor (it doesn't make
sense to «normalize» a Day).
Instead, setters for year, month and day have special semantics
described below.
Getters are always straightforward.
year :: HasDate a => Lens a IntegerSource
adds modL year (+n)n years, matching month and day, with Feb 29th
rolled over to Mar 1st if necessary (like addGregorianYearsRollOver)
month :: HasDate a => Lens a IntSource
adds modL month (+n)n months, with days past the last day of the
month rolling over to the next month (like addGregorianMonthsRollOver)
gregorian :: HasDate a => Lens a (Integer, Int, Int)Source
The semantics of gregorian corresponds to that of toGregorian and
fromGregorian
Time zone
Getting timeZone is straightforward. Setting TimeZone changes both
timeZone and time (and date, if present) in such a way that the new
zoned time corresponds to the same UTC time as the original zoned time.
class HasTime a => HasTimeZone a whereSource
Instances
Re-exports from Data.Time
data Day
The Modified Julian Day is a standard count of days, with zero being the day 1858-11-17.
data TimeOfDay
Time of day as represented in hour, minute and second (with picoseconds), typically used to express local time of day.
data LocalTime
A simple day and time aggregate, where the day is of the specified parameter, and the time is a TimeOfDay. Conversion of this (as local civil time) to UTC depends on the time zone. Conversion of this (as local mean time) to UT1 depends on the longitude.
data ZonedTime
A local time together with a TimeZone.