utc-0.1.0.0: A pragmatic time and date library.

Safe HaskellSafe
LanguageHaskell98

Data.UTC.Class.HasUnixTime

Synopsis

Documentation

class HasUnixTime m where Source

This class defines an interface for contexts that can be asked for a timestamp.

Most users are likely to just need the IO instance, but you might think of other instances:

  • A wrapper around the system clock with internal state that ensures strict monotonically increasing values.
  • A custom monadic computation that needs time, but should not be given IO access.
  • Testing contexts where you might want to inject and test specific timestamps.

Methods

getUnixTime :: (Monad m, IsUnixTime a) => m a Source

Get a timestamp from the surrounding context. The IO instance gives access to the system clock and is what most users are probably looking for.

Beware: The IO instance does not guarantee that subsequent calls are monotonically increasing. The system's clock might stop or even go backwards when synchronised manually or via NTP or when adapting to a leap second.

Example:

import Data.UTC

printCurrentYear :: IO ()
printCurrentYear
  = do now <- getUnixTime :: IO DateTime
       print (year now)

Instances