Package Info

ghc-lens-datetime


Lenses for Data.Time.* types


Development/Libraries/Haskell

The 'lens-datetime' library provides a unified lens based accessors to the various types in 'Data.Time.Clock', 'Data.Time.Calendar' and 'Data.Time.LocalTime'. This library only tries to make some of the common use-cases convenient, it doesn't aim for completeness. If you want completeness and/or efficiency try the 'thyme' package instead (<http://hackage.haskell.org/package/thyme&gt;).

Demonstration of basic uses.

>import Control.Lens >import Data.Time >import Data.Time.Lens > >aDay :: Day >aDay = fromGregorian 2013 08 22 > >aLocal :: LocalTime >aLocal = LocalTime aDay (TimeOfDay 13 45 28) > >aUTC :: UTCTime >aUTC = UTCTime aDay 7458.9

You can then do the following:

>> aLocal ^. years >2013 >> aUTC ^. months >8 >> aLocal & time .~ midnight >2013-08-22 00:00:00 >> aUTC & days .~ 1 & months .~ 1 >2013-01-01 02:04:18.9 UTC

You can manipulate the date-time values with proper roll-over behavior via the 'FlexibleDateTime' mechanism:

>> aLocal & flexDT.months +~ 12 >2014-08-22 13:45:28 >> aUTC & flexDT.days +~ 100 >2013-11-30 02:04:18.9 UTC >> aLocal & flexDT.minutes +~ 120 >2013-08-22 15:45:28 >> aLocal & flexDT %~ ((days +~ 7) . (hours +~ 2)) >2013-08-22 13:45:28.


License: BSD-3-Clause
URL: https://hackage.haskell.org/package/lens-datetime

Categories

Releases

Package Version Update ID Released Package Hub Version Platforms Subpackages
0.3-bp150.2.3 info GA Release 2018-08-01 15
  • AArch64
  • ghc-lens-datetime
  • ghc-lens-datetime-devel
0.3-bp150.2.5 info GA Release 2018-07-30 15
  • ppc64le
  • x86-64
  • ghc-lens-datetime
  • ghc-lens-datetime-devel