Safe Haskell | None |
---|---|
Language | Haskell2010 |
data algorithms related to time (as a Space)
Synopsis
- parseUTCTime :: Text -> Maybe UTCTime
- data TimeGrain
- floorGrain :: TimeGrain -> UTCTime -> UTCTime
- ceilingGrain :: TimeGrain -> UTCTime -> UTCTime
- sensibleTimeGrid :: Pos -> Int -> (UTCTime, UTCTime) -> (TimeGrain, [UTCTime])
- data PosDiscontinuous
- placedTimeLabelDiscontinuous :: PosDiscontinuous -> Maybe Text -> Int -> [UTCTime] -> ([(Int, Text)], [UTCTime])
Documentation
parseUTCTime :: Text -> Maybe UTCTime Source #
parse text as per iso8601
>>>
:set -XOverloadedStrings
>>>
let t0 = parseUTCTime ("2017-12-05" :: Text)
>>>
t0
Just 2017-12-05 00:00:00 UTC
a step in time
Instances
floorGrain :: TimeGrain -> UTCTime -> UTCTime Source #
compute the floor UTCTime based on the timegrain
>>>
floorGrain (Years 5) (UTCTime (fromGregorian 1999 1 1) 0)
1995-12-31 00:00:00 UTC
>>>
floorGrain (Months 3) (UTCTime (fromGregorian 2016 12 30) 0)
2016-09-30 00:00:00 UTC
>>>
floorGrain (Days 5) (UTCTime (fromGregorian 2016 12 30) 1)
2016-12-30 00:00:00 UTC
>>>
floorGrain (Minutes 15) (UTCTime (fromGregorian 2016 12 30) (fromDouble' $ 15*60+1))
2016-12-30 00:15:00 UTC
>>>
floorGrain (Seconds 0.1) (UTCTime (fromGregorian 2016 12 30) 0.12)
2016-12-30 00:00:00.1 UTC
ceilingGrain :: TimeGrain -> UTCTime -> UTCTime Source #
compute the ceiling UTCTime based on the timegrain
>>>
ceilingGrain (Years 5) (UTCTime (fromGregorian 1999 1 1) 0)
2000-12-31 00:00:00 UTC
>>>
ceilingGrain (Months 3) (UTCTime (fromGregorian 2016 12 30) 0)
2016-12-31 00:00:00 UTC
>>>
ceilingGrain (Days 5) (UTCTime (fromGregorian 2016 12 30) 1)
2016-12-31 00:00:00 UTC
>>>
ceilingGrain (Minutes 15) (UTCTime (fromGregorian 2016 12 30) (fromDouble' $ 15*60+1))
2016-12-30 00:30:00 UTC
>>>
ceilingGrain (Seconds 0.1) (UTCTime (fromGregorian 2016 12 30) 0.12)
2016-12-30 00:00:00.2 UTC
sensibleTimeGrid :: Pos -> Int -> (UTCTime, UTCTime) -> (TimeGrain, [UTCTime]) Source #
compute a sensible TimeGrain and list of UTCTimes
>>>
sensibleTimeGrid InnerPos 2 (UTCTime (fromGregorian 2016 12 31) 0, UTCTime (fromGregorian 2017 12 31) 0)
(Months 6,[2016-12-31 00:00:00 UTC,2017-06-30 00:00:00 UTC,2017-12-31 00:00:00 UTC])
>>>
sensibleTimeGrid InnerPos 2 (UTCTime (fromGregorian 2017 1 1) 0, UTCTime (fromGregorian 2017 12 30) 0)
(Months 6,[2017-06-30 00:00:00 UTC])
>>>
sensibleTimeGrid UpperPos 2 (UTCTime (fromGregorian 2017 1 1) 0, UTCTime (fromGregorian 2017 12 30) 0)
(Months 6,[2017-06-30 00:00:00 UTC,2017-12-31 00:00:00 UTC])
>>>
sensibleTimeGrid LowerPos 2 (UTCTime (fromGregorian 2017 1 1) 0, UTCTime (fromGregorian 2017 12 30) 0)
(Months 6,[2016-12-31 00:00:00 UTC,2017-06-30 00:00:00 UTC])
data PosDiscontinuous Source #
whether to include lower and upper times
placedTimeLabelDiscontinuous :: PosDiscontinuous -> Maybe Text -> Int -> [UTCTime] -> ([(Int, Text)], [UTCTime]) Source #
dates attached to charts are often discontinuous, but we want to smooth that reality over and show a continuous range on the axis The assumption with getSensibleTimeGrid is that there is a list of discountinuous UTCTimes rather than a continuous range. Output is a list of index points for the original [UTCTime] and label tuples, and a list of unused list elements.
>>>
placedTimeLabelDiscontinuous PosIncludeBoundaries (Just "%d %b") 2 [UTCTime (fromGregorian 2017 12 6) 0, UTCTime (fromGregorian 2017 12 29) 0, UTCTime (fromGregorian 2018 1 31) 0, UTCTime (fromGregorian 2018 3 3) 0]
([(0,"06 Dec"),(1,"31 Dec"),(2,"28 Feb"),(3,"03 Mar")],[])