o-clock-0.1.0: Type-safe time library.

Safe HaskellNone
LanguageHaskell2010

Time.Series

Contents

Description

This module introduces function to format and parse time in desired way.

Synopsis

Documentation

type AllTimes = '[Fortnight, Week, Day, Hour, Minute, Second, Millisecond, Microsecond, Nanosecond, Picosecond] Source #

Type-level list that consist of all times.

Formatting

class SeriesF (units :: [Rat]) where Source #

Class for time formatting.

Examples

>>> seriesF @'[Day, Hour, Minute, Second] (minute 4000)
"2d18h40m"
>>> seriesF @'[Day, Minute, Second] (minute 4000)
"2d1120m"
>>> seriesF @'[Hour, Minute, Second] (sec 3601)
"1h1s"
>>> seriesF @'[Hour, Second, Millisecond] (Time @Minute $ 3 % 2)
"90s"
>>> seriesF @'[Hour, Second] (minute 0)
"0h"
>>> seriesF @'[Hour, Minute, Second] (Time @Day (2 % 7))
"6h51m25+5/7s"

The received list should be in descending order. It would be verified at compile-time. Example of the error from ghci:

# 127 "srcTimeSeries.hs"

Minimal complete definition

seriesF

Methods

seriesF :: forall (someUnit :: Rat). KnownRatName someUnit => Time someUnit -> String Source #

Instances

SeriesF ([] Rat) Source # 

Methods

seriesF :: KnownRatName someUnit => Time someUnit -> String Source #

(KnownRatName unit, SeriesF ((:) Rat nextUnit units)) => SeriesF ((:) Rat unit ((:) Rat nextUnit units)) Source # 

Methods

seriesF :: KnownRatName someUnit => Time someUnit -> String Source #

KnownRatName unit => SeriesF ((:) Rat unit ([] Rat)) Source # 

Methods

seriesF :: KnownRatName someUnit => Time someUnit -> String Source #

unitsF :: forall unit. KnownRatName unit => Time unit -> String Source #

Similar to seriesF, but formats using all time units of the library.

>>> unitsF $ fortnight 5
"5fn"
>>> unitsF $ minute 4000
"2d18h40m"

Parsing

class SeriesP (units :: [Rat]) where Source #

Class for time parsing.

Empty string on input will be parsed as 0 time of the required time unit:

>>> seriesP @'[Hour, Minute, Second] @Second ""
Just (0s)

Examples

>>> seriesP @'[Day, Hour, Minute, Second] @Minute "2d18h40m"
Just (4000m)
>>> seriesP @'[Day, Minute, Second] @Minute "2d1120m"
Just (4000m)
>>> seriesP @'[Hour, Minute, Second] @Second "1h1s"
Just (3601s)
>>> seriesP @'[Hour, Second, Millisecond] @Minute "90s"
Just (1+1/2m)
>>> seriesP @'[Hour, Second] @Second "11ns"
Nothing
>>> seriesP @'[Hour, Minute] @Minute "1+1/2h"
Nothing
>>> seriesP @'[Hour, Minute] @Minute "1+1/2m"
Just (1+1/2m)
>>> seriesP @'[Hour, Minute] @Minute "1h1+1/2m"
Just (61+1/2m)

Note: The received list should be in descending order. It would be verified at compile-time.

Minimal complete definition

seriesP

Methods

seriesP :: forall (someUnit :: Rat). KnownRatName someUnit => String -> Maybe (Time someUnit) Source #

Instances

SeriesP ([] Rat) Source # 

Methods

seriesP :: KnownRatName someUnit => String -> Maybe (Time someUnit) Source #

(KnownRatName unit, SeriesP ((:) Rat nextUnit units)) => SeriesP ((:) Rat unit ((:) Rat nextUnit units)) Source # 

Methods

seriesP :: KnownRatName someUnit => String -> Maybe (Time someUnit) Source #

KnownRatName unit => SeriesP ((:) Rat unit ([] Rat)) Source # 

Methods

seriesP :: KnownRatName someUnit => String -> Maybe (Time someUnit) Source #

unitsP :: forall unit. KnownRatName unit => String -> Maybe (Time unit) Source #

Similar to seriesP, but parses using all time units of the library.

>>> unitsP @Second "1m"
Just (60s)
>>> unitsP @Minute "2d18h40m"
Just (4000m)