HORIZON HASKELLDocslts/ghc-9.14.x45dd5372026-10-11Search names, modules, packages, or :: a typeCtrl K

GHC 9.14.1 · lts/ghc-9.14.x · 45dd537 · 2026-10-11

Modulethyme-0.4.1Haskell2010

Data.Thyme.Clock

Types and functions for UTC and UT1.

If you don't care about leap seconds, keep to UTCTime and NominalDiffTime for your clock calculations, and you'll be fine.

Data.Thyme.Time provides Num, Real, Fractional and RealFrac instances for DiffTime and NominalDiffTime, but their use is discouraged. See Data.Thyme.Docs#spaces for details.

Use fromSeconds and toSeconds to convert between DiffTime / NominalDiffTime and other numeric types; use fromSeconds' for literals to avoid type defaulting warnings.

  • 5 types
  • 1 class
  • 24 values
  • Packagethyme-0.4.1
  • Exports32
  • LanguageHaskell2010
  • LicenceBSD-3-Clause
  • SourceClock.hs

UTC

13 declarations
newtypenewtype UTCTime
#

Coördinated universal time (UTCTime) is the most commonly used standard for civil timekeeping. It is synchronised with TAI (Data.Thyme.Clock.AbsoluteTime) and both tick in increments of SI seconds, but UTC includes occasional leap-seconds to keep it close to UT1 (UniversalTime).

> utcTime # UTCView (gregorian # YearMonthDay 2016 1 15) (timeOfDay # TimeOfDay 12 34 56.78)
2016-01-15 12:34:56.78 UTC

> UTCTime (gregorian # YearMonthDay 2016 1 15) (timeOfDay # TimeOfDay 12 34 56.78)
2016-01-15 12:34:56.78 UTC

> mkUTCTime 2016 1 15  12 34 56.78
2016-01-15 12:34:56.78 UTC

UTCTime is an AffineSpace with NominalDiffTime as its Diff. See Data.Thyme.Docs#spaces for details.

> let t0 = mkUTCTime 2016 1 15  23 59 0
> let t1 = mkUTCTime 2016 1 16  00  1 1
> let dt = t1 .-. t0
> dt
121s :: NominalDiffTime

> t1 .+^ dt
2016-01-16 00:03:02 UTC

> t1 .+^ 3 *^ dt
2016-01-16 00:07:04 UTC

To decompose a UTCTime into a separate Day and time-of-day, use utcTime. To convert to a local time zone, see zonedTime or utcLocalTime.

Notes

Internally UTCTime is just a 64-bit count of microseconds since the Modified Julian Day epoch, so (.+^), (.-.) et cetera ought to be fast.

UTCTime cannot represent leap seconds. If leap seconds matter, use AbsoluteTime from Data.Thyme.Clock.TAI instead, along with absoluteTime' and UTCView for presentation.

Instances27Bounded, Enum, Eq, Data, Ord, Read, …
valueutcTime :: Iso' UTCTime UTCView
#

View UTCTime as an UTCView, comprising a Day along with a DiffTime offset since midnight.

This is an improper lens: utcvDayTime outside the range of [zeroV, posixDayLength) will carry over into utcvDay, with the expected behaviour.

> view utcTime <$> getCurrentTime
UTCView {utcvDay = 2016-01-15, utcvDayTime = 49322.287688s}

> utcTime # UTCView (gregorian # YearMonthDay 2016 1 15) (timeOfDay # TimeOfDay 12 34 56.78)
2016-01-15 12:34:56.78 UTC

With {-# LANGUAGE ViewPatterns #-}, you can write: e.g.

f :: UTCTime -> (Day, DiffTime)
f (view utcTime -> UTCView day dt) = (day, dt)
datadata UTCView
#

Unpacked UTCTime, partly for compatibility with time.

As of GHC 7.10, you can also use the UTCTime pattern synonym.

Constructors

Instances15Eq, Data, Ord, Read, Show, Generic, …
newtypenewtype NominalDiffTime
#

The nominal interval between two UTCTimes, which does not take leap seconds into account.

For example, the difference between 23:59:59 and 00:00:01 on the following day is always 2 seconds of NominalDiffTime, regardless of whether a leap-second took place.

NominalDiffTime is an instance of AdditiveGroup as well as VectorSpace, with Rational as its Scalar. We do not provide Num, Real, Fractional nor RealFrac instances here. See Data.Thyme.Docs#spaces for details.

> let d = fromSeconds' 2 :: NominalDiffTime
> d
2s
> d ^/ 3
0.666667s

See also: UTCTime.

Instances31Bounded, Enum, Eq, Fractional, Data, Num, …

Absolute intervals

1 declaration
newtypenewtype DiffTime
#

An interval or duration of time, as would be measured by a stopwatch.

DiffTime is an instance of AdditiveGroup as well as VectorSpace, with Rational as its Scalar. We do not provide Num, Real, Fractional nor RealFrac instances here. See Data.Thyme.Docs#spaces for details.

> fromSeconds' 100 :: DiffTime
100s
> fromSeconds' 100 ^+^ fromSeconds' 100 ^* 4
500s
> fromSeconds' 100 ^-^ fromSeconds' 100 ^/ 4
75s
Instances31Bounded, Enum, Eq, Fractional, Data, Num, …

Time interval conversion

6 declarations
classclass (HasBasis t, Basis t ~ (), Scalar t ~ Rational) => TimeDiff t where
#

Time intervals, encompassing both DiffTime and NominalDiffTime.

Notes

Still affected by http://hackage.haskell.org/trac/ghc/ticket/7611?

Methods

Instances2TimeDiff

Universal Time

3 declarations
newtypenewtype UniversalTime
#

The principal form of universal time, namely UT1.

UT1 is defined by the rotation of the Earth around its axis relative to the Sun. The length of each UT1 day varies and is never exactly 86400 SI seconds, unlike UTC or TAI.

The difference between UT1 and UTC is DUT1.

Instances21Bounded, Enum, Eq, Data, Ord, Ix, …

Compatibility

9 declarations