The lens-datetime package

[ Tags: bsd3, data, lenses, library ] [ Propose Tags ]

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).

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

[Skip to Readme]

Properties

Versions 0.1, 0.1.1, 0.2, 0.2.1, 0.3
Dependencies base (>=4.6 && <5), lens (>=3 && <5), time (==1.*) [details]
License BSD3
Author Mihaly Barasz <klao@nilcons.com>
Maintainer Mihaly Barasz <klao@nilcons.com>
Category Data, Lenses
Home page https://github.com/nilcons/lens-datetime
Bug tracker https://github.com/nilcons/lens-datetime/issues
Source repository head: git clone https://github.com/nilcons/lens-datetime.git
Uploaded Fri Apr 29 15:51:42 UTC 2016 by MihalyBarasz
Distributions LTSHaskell:0.3, NixOS:0.3, Stackage:0.3, Tumbleweed:0.3
Downloads 1258 total (18 in the last 30 days)
Rating 2.0 (1 ratings) [clear rating]
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2016-11-26 [all 1 reports]
Hackage Matrix CI

Modules

[Index]

Downloads

Maintainer's Corner

For package maintainers and hackage trustees


Readme for lens-datetime-0.3

[back to package description]

lens-datetime

Haskell library that provides a unified lens based accessors to the various types in Data.Time.Clock and Data.Time.LocalTime.