human-readable-duration-0.2.1.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 :: Seconds -> 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 :: Seconds Source #

one millisecond (0.001)

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

oneSecond :: Seconds Source #

one second (1)

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

minute :: Seconds Source #

number of seconds in one minute

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

hour :: Seconds Source #

number of seconds in one hour

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

day :: Seconds Source #

number of seconds in one day

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

year :: Seconds Source #

number of seconds in one year

>>> year / day
365.000000

getMs :: Seconds -> Integer Source #

number of milli seconds given a duration in micro seconds

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

getSeconds :: Seconds -> Integer Source #

number of seconds given a duration in micro seconds

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

getMinutes :: Seconds -> Integer Source #

number of minutes given a duration in micro seconds

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

getHours :: Seconds -> Integer Source #

number of hours given a duration in micro seconds

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

getDays :: Seconds -> Integer Source #

number of days given a duration in micro seconds

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

getYears :: Seconds -> Integer Source #

number of years given a duration in micro seconds

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