extra-0.3.1: Extra functions I use.

Safe HaskellNone

System.Time.Extra

Synopsis

Documentation

type Seconds = DoubleSource

A type alias for seconds, which are stored as Double.

sleep :: Seconds -> IO ()Source

Sleep for a number of seconds.

 fmap (round . fst) (duration $ sleep 1) == return 1

subtractTime :: UTCTime -> UTCTime -> SecondsSource

Calculate the difference between two times in seconds. Usually the first time will be the end of an event, and the second time will be the beginning.

 \a b -> a > b ==> subtractTime a b > 0

showDuration :: Seconds -> StringSource

Show a number of seconds, typically a duration, in a suitable manner with responable precision for a human.

 showDuration 3.435   == "3.44s"
 showDuration 623.8   == "10m24s"
 showDuration 62003.8 == "17h13m"
 showDuration 1e8     == "27777h47m"

offsetTime :: IO (IO Seconds)Source

Call once to start, then call repeatedly to get the elapsed time since the first call. Values will usually increase, unless the system clock is updated (if you need the guarantee, see offsetTimeIncrease).

offsetTimeIncrease :: IO (IO Seconds)Source

Like offsetTime, but results will never decrease (though they may stay the same).

 do f <- offsetTimeIncrease; xs <- replicateM 10 f; return $ xs == sort xs

duration :: IO a -> IO (Seconds, a)Source

Record how long a computation takes in Seconds.