| Safe Haskell | None |
|---|---|
| Language | Haskell98 |
Data.Time.Lens
Synopsis
- 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
Minimal complete definition
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.
Minimal complete definition
year :: HasDate a => Lens a Integer #
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 Int #
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) #
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 where #
Minimal complete definition
Instances
| HasTimeZone ZonedTime # | |
Re-exports from Data.Time
The Modified Julian Day is a standard count of days, with zero being the day 1858-11-17.
Instances
| Enum Day | |
| Eq Day | |
| Data Day | |
Defined in Data.Time.Calendar.Days Methods gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Day -> c Day # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c Day # dataTypeOf :: Day -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c Day) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Day) # gmapT :: (forall b. Data b => b -> b) -> Day -> Day # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Day -> r # gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Day -> r # gmapQ :: (forall d. Data d => d -> u) -> Day -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> Day -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> Day -> m Day # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Day -> m Day # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Day -> m Day # | |
| Ord Day | |
| Ix Day | |
| NFData Day | |
Defined in Data.Time.Calendar.Days | |
| ParseTime Day | |
Defined in Data.Time.Format.Parse | |
| HasDate Day # | |
Time of day as represented in hour, minute and second (with picoseconds), typically used to express local time of day.
Instances
| Eq TimeOfDay | |
| Data TimeOfDay | |
Defined in Data.Time.LocalTime.Internal.TimeOfDay Methods gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> TimeOfDay -> c TimeOfDay # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c TimeOfDay # toConstr :: TimeOfDay -> Constr # dataTypeOf :: TimeOfDay -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c TimeOfDay) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c TimeOfDay) # gmapT :: (forall b. Data b => b -> b) -> TimeOfDay -> TimeOfDay # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> TimeOfDay -> r # gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> TimeOfDay -> r # gmapQ :: (forall d. Data d => d -> u) -> TimeOfDay -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> TimeOfDay -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> TimeOfDay -> m TimeOfDay # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> TimeOfDay -> m TimeOfDay # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> TimeOfDay -> m TimeOfDay # | |
| Ord TimeOfDay | |
Defined in Data.Time.LocalTime.Internal.TimeOfDay | |
| Show TimeOfDay | |
| NFData TimeOfDay | |
Defined in Data.Time.LocalTime.Internal.TimeOfDay | |
| ParseTime TimeOfDay | |
Defined in Data.Time.Format.Parse | |
| HasTime TimeOfDay # | |
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.
Instances
| Eq LocalTime | |
| Data LocalTime | |
Defined in Data.Time.LocalTime.Internal.LocalTime Methods gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> LocalTime -> c LocalTime # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c LocalTime # toConstr :: LocalTime -> Constr # dataTypeOf :: LocalTime -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c LocalTime) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c LocalTime) # gmapT :: (forall b. Data b => b -> b) -> LocalTime -> LocalTime # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> LocalTime -> r # gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> LocalTime -> r # gmapQ :: (forall d. Data d => d -> u) -> LocalTime -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> LocalTime -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> LocalTime -> m LocalTime # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> LocalTime -> m LocalTime # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> LocalTime -> m LocalTime # | |
| Ord LocalTime | |
Defined in Data.Time.LocalTime.Internal.LocalTime | |
| Show LocalTime | |
| NFData LocalTime | |
Defined in Data.Time.LocalTime.Internal.LocalTime | |
| ParseTime LocalTime | |
Defined in Data.Time.Format.Parse | |
| HasDate LocalTime # | |
| HasTime LocalTime # | |
A local time together with a time zone.
Instances
| Data ZonedTime | |
Defined in Data.Time.LocalTime.Internal.ZonedTime Methods gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> ZonedTime -> c ZonedTime # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c ZonedTime # toConstr :: ZonedTime -> Constr # dataTypeOf :: ZonedTime -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c ZonedTime) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c ZonedTime) # gmapT :: (forall b. Data b => b -> b) -> ZonedTime -> ZonedTime # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> ZonedTime -> r # gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> ZonedTime -> r # gmapQ :: (forall d. Data d => d -> u) -> ZonedTime -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> ZonedTime -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> ZonedTime -> m ZonedTime # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> ZonedTime -> m ZonedTime # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> ZonedTime -> m ZonedTime # | |
| Show ZonedTime | |
| NFData ZonedTime | |
Defined in Data.Time.LocalTime.Internal.ZonedTime | |
| ParseTime ZonedTime | |
Defined in Data.Time.Format.Parse | |
| HasTimeZone ZonedTime # | |
| HasDate ZonedTime # | |
| HasTime ZonedTime # | |
getZonedTime :: IO ZonedTime #
Re-exports from Data.Lens.Light
Simple lens data type