human-readable-duration-0.2.0.1: Provide duration helper

Safe HaskellSafe
LanguageHaskell2010

Data.Duration

Description

This is a minimal Haskell library to display duration.

 > let duration = 2 * ms + 3 * oneSecond + 2 * minute + 33*day + 2*year
 > humanReadableDuration duration
 "2 years 33 days 2 min 3s 2ms"
 > getYears duration
 2
 > getDays duration
 763
 > getMs duration
 65923323002
 

Synopsis

Documentation

humanReadableDuration :: Micro -> String Source

humanReadableDuration take some time in micro-second precision and render a human readable duration.

>>> let duration = 2 * ms + 3 * oneSecond + 2 * minute + 33*day + 2*year
>>> duration
65923323.002000
>>> humanReadableDuration duration
"2 years 33 days 2 min 3s 2ms"

humanReadableDuration' :: Real a => a -> String Source

Wrapper around any Real input, which works for DiffTime and NominalDiffTime from the time library, or a Double of seconds.

>>> import Data.Time.Clock
>>> humanReadableDuration' (secondsToDiffTime 10)
"10s "

ms :: Micro Source

 one millisecond (0.001)

>>> ms
0.001000
>>> 1000 * ms
1.000000

oneSecond :: Micro Source

 one second (1)

>>> oneSecond / ms
1000.000000
>>> oneSecond
1.000000

minute :: Micro Source

 number of seconds in one minute

>>> minute / oneSecond
60.000000
>>> minute / ms
60000.000000

hour :: Micro Source

 number of seconds in one hour

>>> hour / minute
60.000000
>>> hour / oneSecond
3600.000000

day :: Micro Source

 number of seconds in one day

>>> day / hour
24.000000
>>> day / oneSecond
86400.000000

year :: Micro Source

 number of seconds in one year

>>> year / day
365.000000

getMs :: Micro -> Integer Source

 number of milli seconds given a duration in micro seconds

>>> getMs 1
1000
>>> getMs 1.618033
1618

getSeconds :: Micro -> Integer Source

 number of seconds given a duration in micro seconds

>>> getSeconds 1
1
>>> getSeconds 1.618033
1

getMinutes :: Micro -> Integer Source

 number of minutes given a duration in micro seconds

>>> getMinutes 60
1
>>> getMinutes 59
0

getHours :: Micro -> Integer Source

 number of hours given a duration in micro seconds

>>> getHours 3600
1
>>> getHours (60 * minute)
1
>>> getHours (2 * day)
48

getDays :: Micro -> Integer Source

 number of days given a duration in micro seconds

>>> getDays (10 * day)
10
>>> getDays (240 * hour)
10

getYears :: Micro -> Integer Source

 number of years given a duration in micro seconds

>>> getYears (720 * day)
1
>>> getYears (740 * day)
2