MissingH-1.2.0.0: Large utility library

Portability | portable
Stability | provisional
Maintainer | John Goerzen <jgoerzen@complete.org>
Safe Haskell | None

System.Time.Utils

Description

This module provides various Haskell utilities for dealing with times and dates.

Written by John Goerzen, jgoerzen@complete.org

Synopsis

- timelocal :: CalendarTime -> IO Integer
- timegm :: CalendarTime -> Integer
- timeDiffToSecs :: TimeDiff -> Integer
- epoch :: CalendarTime
- epochToClockTime :: Real a => a -> ClockTime
- clockTimeToEpoch :: Num a => ClockTime -> a
- renderSecs :: Integer -> String
- renderTD :: TimeDiff -> String

# Documentation

timelocal :: CalendarTime -> IO Integer

Converts the specified CalendarTime (see System.Time) to seconds-since-epoch format.

The input CalendarTime is assumed to be the time as given in your local timezone. All timezone and DST fields in the object are ignored.

This behavior is equivolent to the timelocal() and mktime() functions that C programmers are accustomed to.

Please note that the behavior for this function during the hour immediately before or after a DST switchover may produce a result with a different hour than you expect.

timegm :: CalendarTime -> Integer

Converts the specified CalendarTime (see System.Time) to seconds-since-epoch time.

This conversion does respect the timezone specified on the input object. If you want a conversion from UTC, specify ctTZ = 0 and ctIsDST = False.

When called like that, the behavior is equivolent to the GNU C function timegm(). Unlike the C library, Haskell's CalendarTime supports timezone information, so if such information is specified, it will impact the result.

timeDiffToSecs :: TimeDiff -> Integer

Converts the given timeDiff to the number of seconds it represents.

Uses the same algorithm as normalizeTimeDiff in GHC.

epoch :: CalendarTime

January 1, 1970, midnight, UTC, represented as a CalendarTime.

epochToClockTime :: Real a => a -> ClockTime

Converts an Epoch time represented with an arbitrary Real to a ClockTime. This input could be a CTime from Foreign.C.Types or an EpochTime from System.Posix.Types.

clockTimeToEpoch :: Num a => ClockTime -> a

Converts a ClockTime to something represented with an arbitrary Real. The result could be treated as a CTime from Foreign.C.Types or EpochTime from System.Posix.Types. The inverse of `epochToClockTime`.

Fractions of a second are not preserved by this function.

renderSecs :: Integer -> String

Render a number of seconds as a human-readable amount. Shows the two most significant places. For instance:

    renderSecs 121 = "2m1s"

See also `renderTD` for a function that works on a TimeDiff.

renderTD :: TimeDiff -> String

Like `renderSecs`, but takes a TimeDiff instead of an integer second count.