This module defines types for many useful time periods, as well as mechanisms for converting between them.
- class TimeUnit a where
- toMicroseconds :: a -> Integer
- fromMicroseconds :: Integer -> a
- data Attosecond
- data Femtosecond
- data Picosecond
- data Nanosecond
- data Microsecond
- data Millisecond
- data Second
- data Minute
- data Hour
- data Day
- data Week
- data Fortnight
- addTime :: (TimeUnit a, TimeUnit b, TimeUnit c) => a -> b -> c
- subTime :: (TimeUnit a, TimeUnit b, TimeUnit c) => a -> b -> c
- convertUnit :: (TimeUnit a, TimeUnit b) => a -> b
- getCPUTimeWithUnit :: TimeUnit a => IO a
Documentation
A generic class that describes all the units of time. We use microseconds here because that tends to be what GHC (at least) tends to use as its system-level minimum tick size.
toMicroseconds :: a -> IntegerSource
Converts the given unit of time into microseconds, flooring the value if it comes to a fractional number of microseconds. (In other words: be careful, you may lose precision!)
fromMicroseconds :: Integer -> aSource
Converts the given number of microseconds into the unit of time, flooring the value if it comes to a fraction number of the given unit. (In other words: be careful, you may lose precision!)
data Attosecond Source
data Femtosecond Source
data Picosecond Source
data Nanosecond Source
data Microsecond Source
data Millisecond Source
addTime :: (TimeUnit a, TimeUnit b, TimeUnit c) => a -> b -> cSource
Add two times together to get a useful third time unit. As per usual, you'll want to make sure that you are careful regarding precision. This function goes through microseconds as an intermediary form.
subTime :: (TimeUnit a, TimeUnit b, TimeUnit c) => a -> b -> cSource
Subtract the second time from the first, to get a useful third time unit. As per usual, you'll want to make sure that you are careful regarding precision. This function goes through microseconds as an intermediary form.
convertUnit :: (TimeUnit a, TimeUnit b) => a -> bSource
Convert one time unit to another. Note that if you move from a smaller time unit to a larger one, or between two time units smaller than a microsecond, you will lose precision.
getCPUTimeWithUnit :: TimeUnit a => IO aSource
Get the current CPU time in your favorite units. This is probably not very useful in itself, but is likely useful for comparison purposes ...