system-time-monotonic-0.1: Simple library for using the system's monotonic clock

PortabilityTested on Linux and Windows
Safe HaskellSafe-Infered




This module provides more direct access to the system's monotonic clock, but provides less protection against wraparound.

More specifically, in the higher-level System.Time.Monotonic API, Clock updates its internal disposition every time clockGetTime is called. The only way to get a wraparound issue with the higher-level API is to call clockGetTime very seldomly (e.g. less than once every 24.8 days, if GetTickCount is being used).



getSystemClock :: IO SomeSystemClockSource

Return a module used for accessing the system's monotonic clock. The reason this is an IO action, rather than simply a SystemClock value, is that the implementation may need to make a system call to determine what monotonic time source to use, and how to use it.

data SomeSystemClock Source

Existentially-quantified wrapper around SystemClock


forall time . SomeSystemClock (SystemClock time) 

data SystemClock time Source




systemClockGetTime :: IO time
systemClockDiffTime :: time -> time -> DiffTime

systemClockDiffTime new old returns the amount of time that has elapsed between two calls to systemClockGetTime.

This function should handle wraparound properly. Also, bear in mind that new may be earlier than old. This can happen if multiple threads are accessing a Clock simultaneously.

systemClockName :: String

Label identifying this clock, like "clock_gettime(CLOCK_MONOTONIC)" or "GetTickCount". This label is used for the Show instances of SystemClock and SomeSystemClock, and for clockDriverName.


Show (SystemClock time) 


The set of definitions below is platform-dependent.

systemClock_MONOTONIC :: SystemClock CTimeSpecSource

Uses clock_gettime with CLOCK_MONOTONIC.

Warning: on Linux, this clock stops when the computer is suspended. See