time-lens-0.3: Lens-based interface to Data.Time data structures

Safe HaskellSafe-Infered





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 modL minutes (+5) will correctly add 5 minutes to the time, e.g.

>>> modL minutes (+5) (TimeOfDay 16 57 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)


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

modL year (+n) adds n years, matching month and day, with Feb 29th rolled over to Mar 1st if necessary (like addGregorianYearsRollOver)

month :: HasDate a => Lens a IntSource

modL month (+n) adds n months, with days past the last day of the month rolling over to the next month (like addGregorianMonthsRollOver)

day :: HasDate a => Lens a IntSource

modL day (+n) computes the date n days after the original date (like addDays)

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.

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.

Re-exports from Data.Lens.Common

data Lens a b

getL :: Lens a b -> a -> b

Gets the getter function from a lens.

modL :: Lens a b -> (b -> b) -> a -> a

Gets the modifier function from a lens.

setL :: Lens a b -> b -> a -> a

Gets the setter function from a lens.