numhask-space-0.6.1: numerical spaces

Safe HaskellNone
LanguageHaskell2010

NumHask.Space.Time

Description

data algorithms related to time (as a Space)

Synopsis

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

data TimeGrain Source #

a step in time

Instances
Eq TimeGrain Source # 
Instance details

Defined in NumHask.Space.Time

Show TimeGrain Source # 
Instance details

Defined in NumHask.Space.Time

Generic TimeGrain Source # 
Instance details

Defined in NumHask.Space.Time

Associated Types

type Rep TimeGrain :: Type -> Type #

type Rep TimeGrain Source # 
Instance details

Defined in NumHask.Space.Time

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) (toDiffTime $ 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) (toDiffTime $ 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 used for time series analysis or 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")],[])

placedTimeLabelContinuous :: PosDiscontinuous -> Maybe Text -> Int -> (UTCTime, UTCTime) -> [(Double, Text)] Source #

A sensible time grid between two dates, projected onto (0,1) with no attempt to get finnicky.

>>> placedTimeLabelContinuous PosIncludeBoundaries (Just "%d %b") 2 (UTCTime (fromGregorian 2017 12 6) 0, UTCTime (fromGregorian 2017 12 29) 0)
[(0.0,"06 Dec"),(0.4347826086956521,"16 Dec"),(0.8695652173913042,"26 Dec"),(0.9999999999999999,"29 Dec")]