duration-0.2.0.0: A tiny compile-time time utility library inspired by zeit/ms

Data.Time.Clock.Duration

Contents

Description

A tiny compile-time time utility library, inspired by zeit/ms.

Synopsis

# Quasiquoters

A quasiquoter to denote a duration.

>>> [t| 42s |] :: DiffTime
42s

>>> [t| 1day |] :: DiffTime
86400s


The expression has the type of AbsoluteDuration a => a.

>>> [t| 1ms |] :: NominalDiffTime
0.001s

>>> [t| 1ms |] :: CSUSeconds
1000

>>> [t| 1ms |] :: CUSeconds
1000


You can use various expressions inside the quasiquoter. (See Time for details.)

>>> [t| 1ms |] :: DiffTime
0.001s

>>> [t| 1s |] :: DiffTime
1s

>>> [t| 1m |] :: DiffTime
60s

>>> [t| 1h |] :: DiffTime
3600s

>>> [t| 1d |] :: DiffTime
86400s

>>> [t| 1w |] :: DiffTime
604800s

>>> [t| 1y |] :: DiffTime
31536000s


A quasiquoter to denote a duration in seconds. Its behavior varies according to what you give to the quasiquoter.

When a unitless number (like 42) is supplied to s, the expression has the type of AbsoluteDuration a => a.

>>> [s| 42 |] :: DiffTime
42s


When you pass a string with a number and a valid unit (like 42s), the expression has the type of RelativeDuration a => a, and it represents how long the given duration is in seconds.

For example, how long is 42 minutes in seconds?

>>> [s| 42m |] :: Int
2520


Note that short durations can be rounded to zero when treated as an integer.

>>> [s| 1ms |] :: Int
0
>>> [s| 1ms |] :: Integer
0


To avoid this, use Ratio or Float instead.

>>> [s| 1ms |] :: Rational
1 % 1000
>>> [s| 1ms |] :: Float
1.0e-3


A quasiquoter to denote a duration in milliseconds. See s for detailed usage.

>>> [ms| 42 |] :: DiffTime
0.042s

>>> [ms| 42s |] :: Integer
42000


A quasiquoter to denote a duration in microseconds. See s for detailed usage.

>>> [µs| 42 |] :: DiffTime
0.000042s

>>> [µs| 42s |] :: Integer
42000000


A quasiquoter to denote a duration in nanoseconds. See s for detailed usage.

>>> [ns| 42 |] :: DiffTime
0.000000042s

>>> [ns| 42s |] :: Integer
42000000000


A quasiquoter to denote a duration in picoseconds. See s for detailed usage.

>>> [ps| 42 |] :: DiffTime
0.000000000042s

>>> [ps| 42s |] :: Integer
42000000000000