Safe Haskell | None |
---|---|

Language | Haskell2010 |

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

## Synopsis

- type AllTimes = '[Fortnight, Week, Day, Hour, Minute, Second, Millisecond, Microsecond, Nanosecond, Picosecond]
- type family (from :: Rat) ... (to :: Rat) :: [Rat] where ...
- class SeriesF (units :: [Rat]) where
- seriesF :: forall (someUnit :: Rat). KnownRatName someUnit => Time someUnit -> String

- unitsF :: forall unit. KnownRatName unit => Time unit -> String
- class SeriesP (units :: [Rat]) where
- unitsP :: forall unit. KnownRatName unit => String -> Maybe (Time unit)

# Documentation

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

Type-level list that consist of all times.

type family (from :: Rat) ... (to :: Rat) :: [Rat] where ... Source #

Creates the list of time units in descending order by provided the highest and the lowest bound of the desired list. Throws the error when time units are not in the right order.

**Usage example:**

`>>>`

"3h5m3+123/1000s"`seriesF @(Hour ... Second) $ hour 3 +:+ minute 5 +:+ sec 3 +:+ ms 123`

# Formatting

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

Class for time formatting.

**Examples**

`>>>`

"2d18h40m"`seriesF @'[Day, Hour, Minute, Second] (minute 4000)`

`>>>`

"2d1120m"`seriesF @'[Day, Minute, Second] (minute 4000)`

`>>>`

"1h1s"`seriesF @'[Hour, Minute, Second] (sec 3601)`

`>>>`

"90s"`seriesF @'[Hour, Second, Millisecond] (Time @Minute $ 3 % 2)`

`>>>`

"0h"`seriesF @'[Hour, Second] (minute 0)`

`>>>`

"6h51m25+5/7s"`seriesF @'[Hour, Minute, Second] (Time @Day (2 % 7))`

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

:

`>>>`

... • List of units should be in descending order • In the expression: seriesF @'[Millisecond, Second] (minute 42) In an equation for ‘it’: it = seriesF @'[Millisecond, Second] (minute 42) ...`seriesF @'[Millisecond, Second] (minute 42)`

## Instances

SeriesF ([] :: [Rat]) Source # | |

Defined in Time.Series | |

(KnownRatName unit, SeriesF (nextUnit ': units), DescendingConstraint (IsDescending (unit ': (nextUnit ': units)))) => SeriesF (unit ': (nextUnit ': units)) Source # | |

Defined in Time.Series | |

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

Defined in Time.Series |

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

Similar to `seriesF`

, but formats using all time units of the library.

`>>>`

"5fn"`unitsF $ fortnight 5`

`>>>`

"2d18h40m"`unitsF $ minute 4000`

# 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:

`>>>`

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

**Examples**

`>>>`

Just (4000m)`seriesP @'[Day, Hour, Minute, Second] @Minute "2d18h40m"`

`>>>`

Just (4000m)`seriesP @'[Day, Minute, Second] @Minute "2d1120m"`

`>>>`

Just (3601s)`seriesP @'[Hour, Minute, Second] @Second "1h1s"`

`>>>`

Just (1+1/2m)`seriesP @'[Hour, Second, Millisecond] @Minute "90s"`

`>>>`

Nothing`seriesP @'[Hour, Second] @Second "11ns"`

`>>>`

Nothing`seriesP @'[Hour, Minute] @Minute "1+1/2h"`

`>>>`

Just (1+1/2m)`seriesP @'[Hour, Minute] @Minute "1+1/2m"`

`>>>`

Just (61+1/2m)`seriesP @'[Hour, Minute] @Minute "1h1+1/2m"`

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

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

## Instances

SeriesP ([] :: [Rat]) Source # | |

Defined in Time.Series | |

(KnownRatName unit, SeriesP (nextUnit ': units), DescendingConstraint (IsDescending (unit ': (nextUnit ': units)))) => SeriesP (unit ': (nextUnit ': units)) Source # | |

Defined in Time.Series | |

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

Defined in Time.Series |