Safe Haskell | None |
---|---|
Language | Haskell98 |
This module defines types for many useful time periods, as well as mechanisms for converting between them.
Synopsis
-
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
class TimeUnit a where Source #
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 -> Integer Source #
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 -> a Source #
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!)
Instances
data Attosecond Source #
Instances
data Femtosecond Source #
Instances
data Picosecond Source #
Instances
data Nanosecond Source #
Instances
data Microsecond Source #
Instances
data Millisecond Source #
Instances
Instances
Instances
Instances
Enum Hour Source # | |
Eq Hour Source # | |
Integral Hour Source # | |
Defined in Data.Time.Units |
|
Data Hour Source # | |
Defined in Data.Time.Units gfoldl :: ( forall d b. Data d => c (d -> b) -> d -> c b) -> ( forall g. g -> c g) -> Hour -> c Hour Source # gunfold :: ( forall b r. Data b => c (b -> r) -> c r) -> ( forall r. r -> c r) -> Constr -> c Hour Source # toConstr :: Hour -> Constr Source # dataTypeOf :: Hour -> DataType Source # dataCast1 :: Typeable t => ( forall d. Data d => c (t d)) -> Maybe (c Hour ) Source # dataCast2 :: Typeable t => ( forall d e. ( Data d, Data e) => c (t d e)) -> Maybe (c Hour ) Source # gmapT :: ( forall b. Data b => b -> b) -> Hour -> Hour Source # gmapQl :: (r -> r' -> r) -> r -> ( forall d. Data d => d -> r') -> Hour -> r Source # gmapQr :: forall r r'. (r' -> r -> r) -> r -> ( forall d. Data d => d -> r') -> Hour -> r Source # gmapQ :: ( forall d. Data d => d -> u) -> Hour -> [u] Source # gmapQi :: Int -> ( forall d. Data d => d -> u) -> Hour -> u Source # gmapM :: Monad m => ( forall d. Data d => d -> m d) -> Hour -> m Hour Source # gmapMp :: MonadPlus m => ( forall d. Data d => d -> m d) -> Hour -> m Hour Source # gmapMo :: MonadPlus m => ( forall d. Data d => d -> m d) -> Hour -> m Hour Source # |
|
Num Hour Source # | |
Ord Hour Source # | |
Read Hour Source # | |
Real Hour Source # | |
Defined in Data.Time.Units toRational :: Hour -> Rational Source # |
|
Show Hour Source # | |
Ix Hour Source # | |
Defined in Data.Time.Units |
|
TimeUnit Hour Source # | |
Defined in Data.Time.Units toMicroseconds :: Hour -> Integer Source # fromMicroseconds :: Integer -> Hour Source # |
Instances
Enum Day Source # | |
Eq Day Source # | |
Integral Day Source # | |
Data Day Source # | |
Defined in Data.Time.Units gfoldl :: ( forall d b. Data d => c (d -> b) -> d -> c b) -> ( forall g. g -> c g) -> Day -> c Day Source # gunfold :: ( forall b r. Data b => c (b -> r) -> c r) -> ( forall r. r -> c r) -> Constr -> c Day Source # toConstr :: Day -> Constr Source # dataTypeOf :: Day -> DataType Source # dataCast1 :: Typeable t => ( forall d. Data d => c (t d)) -> Maybe (c Day ) Source # dataCast2 :: Typeable t => ( forall d e. ( Data d, Data e) => c (t d e)) -> Maybe (c Day ) Source # gmapT :: ( forall b. Data b => b -> b) -> Day -> Day Source # gmapQl :: (r -> r' -> r) -> r -> ( forall d. Data d => d -> r') -> Day -> r Source # gmapQr :: forall r r'. (r' -> r -> r) -> r -> ( forall d. Data d => d -> r') -> Day -> r Source # gmapQ :: ( forall d. Data d => d -> u) -> Day -> [u] Source # gmapQi :: Int -> ( forall d. Data d => d -> u) -> Day -> u Source # gmapM :: Monad m => ( forall d. Data d => d -> m d) -> Day -> m Day Source # gmapMp :: MonadPlus m => ( forall d. Data d => d -> m d) -> Day -> m Day Source # gmapMo :: MonadPlus m => ( forall d. Data d => d -> m d) -> Day -> m Day Source # |
|
Num Day Source # | |
Ord Day Source # | |
Read Day Source # | |
Real Day Source # | |
Defined in Data.Time.Units toRational :: Day -> Rational Source # |
|
Show Day Source # | |
Ix Day Source # | |
Defined in Data.Time.Units |
|
TimeUnit Day Source # | |
Defined in Data.Time.Units toMicroseconds :: Day -> Integer Source # fromMicroseconds :: Integer -> Day Source # |
Instances
Enum Week Source # | |
Eq Week Source # | |
Integral Week Source # | |
Defined in Data.Time.Units |
|
Data Week Source # | |
Defined in Data.Time.Units gfoldl :: ( forall d b. Data d => c (d -> b) -> d -> c b) -> ( forall g. g -> c g) -> Week -> c Week Source # gunfold :: ( forall b r. Data b => c (b -> r) -> c r) -> ( forall r. r -> c r) -> Constr -> c Week Source # toConstr :: Week -> Constr Source # dataTypeOf :: Week -> DataType Source # dataCast1 :: Typeable t => ( forall d. Data d => c (t d)) -> Maybe (c Week ) Source # dataCast2 :: Typeable t => ( forall d e. ( Data d, Data e) => c (t d e)) -> Maybe (c Week ) Source # gmapT :: ( forall b. Data b => b -> b) -> Week -> Week Source # gmapQl :: (r -> r' -> r) -> r -> ( forall d. Data d => d -> r') -> Week -> r Source # gmapQr :: forall r r'. (r' -> r -> r) -> r -> ( forall d. Data d => d -> r') -> Week -> r Source # gmapQ :: ( forall d. Data d => d -> u) -> Week -> [u] Source # gmapQi :: Int -> ( forall d. Data d => d -> u) -> Week -> u Source # gmapM :: Monad m => ( forall d. Data d => d -> m d) -> Week -> m Week Source # gmapMp :: MonadPlus m => ( forall d. Data d => d -> m d) -> Week -> m Week Source # gmapMo :: MonadPlus m => ( forall d. Data d => d -> m d) -> Week -> m Week Source # |
|
Num Week Source # | |
Ord Week Source # | |
Read Week Source # | |
Real Week Source # | |
Defined in Data.Time.Units toRational :: Week -> Rational Source # |
|
Show Week Source # | |
Ix Week Source # | |
Defined in Data.Time.Units |
|
TimeUnit Week Source # | |
Defined in Data.Time.Units toMicroseconds :: Week -> Integer Source # fromMicroseconds :: Integer -> Week Source # |
Instances
addTime :: ( TimeUnit a, TimeUnit b, TimeUnit c) => a -> b -> c Source #
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 -> c Source #
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 -> b Source #
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 a Source #
Get the current CPU time in your favorite units. This is probably not very useful in itself, but is likely useful for comparison purposes ...