time-units-1.0.0: A basic library for defining units of time as types.

Data.Time.Units

Description

This module defines types for many useful time periods, as well as mechanisms for converting between them.

Synopsis

Documentation

class TimeUnit a whereSource

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.

Methods

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!)

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 ...