HORIZON HASKELLDocslts/ghc-9.10.x248f8f02026-10-05Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · 248f8f0 · 2026-10-05

Modulehourglass-0.2.12Haskell2010

Data.Hourglass

Types and methods for time manipulation.

The most basic type for time representation is Elapsed, which represent a number of elapsed seconds since the unix epoch.

Every other defined types can be convert to and from Elapsed type:

timeGetElapsed (Date 1 2 3) :: Elapsed
timeFromElapsed 123         :: DateTime

Local time is represented by any other time types (Elapsed, Date, DateTime, ..), but augmented by a Timezone offset in minutes.

localTime (Date 2014 May 4) 600 -- local time at UTC+10 of May 4th 2014
  • 12 types
  • 5 classes
  • 25 values
  • Packagehourglass-0.2.12
  • Exports42
  • LanguageHaskell2010
  • LicenceBSD-3-Clause
  • SourceHourglass.hs
classclass Timeable t => Time t where
#

Represent time types that can be created from other time types.

Every conversion happens throught ElapsedP or Elapsed types.

Methods

  • timeFromElapsedP :: ElapsedP -> t

    convert from a number of elapsed seconds and nanoseconds to another time representation

  • timeFromElapsed :: Elapsed -> t

    convert from a number of elapsed seconds and nanoseconds to another time representation

    defaults to timeFromElapsedP unless defined explicitely by an instance.

Instances7Time, …
  • Time CTimeDefined in hourglass-0.2.12 · Data.Hourglass.Time
  • Time DateDefined in hourglass-0.2.12 · Data.Hourglass.Time
  • Time DateTimeDefined in hourglass-0.2.12 · Data.Hourglass.Time
  • Time ElapsedDefined in hourglass-0.2.12 · Data.Hourglass.Time
  • Time ElapsedPDefined in hourglass-0.2.12 · Data.Hourglass.Time
  • Epoch epoch => Time (ElapsedSince epoch)Defined in hourglass-0.2.12 · Data.Hourglass.Epoch
  • Epoch epoch => Time (ElapsedSinceP epoch)Defined in hourglass-0.2.12 · Data.Hourglass.Epoch
classclass TimeInterval i where
#

Represent any time interval that has an equivalent value to a number of seconds.

Methods

Instances5TimeInterval
newtypenewtype Elapsed
#

A number of seconds elapsed since the unix epoch.

Constructors

Instances9Eq, Data, Num, Ord, Read, Show, …
datadata ElapsedP
#

A number of seconds and nanoseconds elapsed since the unix epoch.

Instances10Eq, Data, Num, Ord, Read, Real, …
classclass Timeable t where
#

Timeable represent every type that can be made to look like time types.

  • can be converted to ElapsedP and Elapsed

  • optionally have a timezone associated

  • have nanoseconds accessor (which can return 0 when the type is not more precise than seconds)

Methods

  • timeGetElapsedP :: t -> ElapsedP

    convert a time representation to the number of elapsed seconds and nanoseconds to a specific epoch

  • timeGetElapsed :: t -> Elapsed

    convert a time representation to the number of elapsed seconds to a specific epoch.

    defaults to timeGetElapsedP unless defined explicitely by an instance

  • timeGetNanoSeconds :: t -> NanoSeconds

    return the number of optional nanoseconds.

    If the underlaying type is not precise enough to record nanoseconds (or any variant between seconds and nanoseconds), 0 should be returned

    defaults to timeGetElapsedP unless defined explicitely by an instance, for efficiency reason, it's a good idea to override this methods if you know the type is not more precise than Seconds.

Instances7Timeable, …
datadata Duration
#

An amount of time in terms of constant value like hours (3600 seconds), minutes (60 seconds), seconds and nanoseconds.

Constructors

Instances9Eq, Data, Ord, Read, Show, Semigroup, …
datadata Period
#

An amount of conceptual calendar time in terms of years, months and days.

This allow calendar manipulation, representing things like days and months irrespective on how long those are related to timezone and daylight changes.

See Duration for the time-based equivalent to this class.

Instances8Eq, Data, Ord, Read, Show, Semigroup, …
  • Eq PeriodDefined in hourglass-0.2.12 · Data.Hourglass.Diff
  • Data PeriodDefined in hourglass-0.2.12 · Data.Hourglass.Diff
  • Ord PeriodDefined in hourglass-0.2.12 · Data.Hourglass.Diff
  • Read PeriodDefined in hourglass-0.2.12 · Data.Hourglass.Diff
  • Show PeriodDefined in hourglass-0.2.12 · Data.Hourglass.Diff
  • Semigroup PeriodDefined in hourglass-0.2.12 · Data.Hourglass.Diff
  • Monoid PeriodDefined in hourglass-0.2.12 · Data.Hourglass.Diff
  • NFData PeriodDefined in hourglass-0.2.12 · Data.Hourglass.Diff
valuetimeAdd :: (Time t, TimeInterval ti) => t -> ti -> t
#

add some time interval to a time representation and returns this new time representation

example:

t1 `timeAdd` mempty { durationHours = 12 }
valuetimeDiff :: (Timeable t1, Timeable t2) => t1 -> t2 -> Seconds
#

Get the difference in seconds between two time representation

effectively:

t2 `timeDiff` t1 = t2 - t1
datadata TimeFormatElem
#

All the various formatter that can be part of a time format string

Constructors

Instances3Eq, Show, TimeFormat
classclass TimeFormat format where
#

A generic class for anything that can be considered a Time Format string.

Methods

Instances5TimeFormat
valuetimePrint
  1. :: (TimeFormat format, Timeable t)
  2. => format

    the format to use for printing

  3. -> t

    the global time to print

  4. -> String

    the resulting string

#

Pretty print time to a string

The actual output is determined by the format used

valuelocalTimePrint
  1. :: (TimeFormat format, Timeable t)
  2. => format

    the format to use for printing

  3. -> LocalTime t

    the local time to print

  4. -> String

    the resulting local time string

#

Pretty print local time to a string.

The actual output is determined by the format used.

datadata LocalTime t
#

Local time representation

this is a time representation augmented by a timezone to get back to a global time, the timezoneOffset needed to be added to the local time.

Instances4Functor, Eq, Ord, Show
valuelocalTime :: Time t => TimezoneOffset -> t -> LocalTime t
#

Create a local time type from a timezone and a time type.

The time value is assumed to be local to the timezone offset set, so no transformation is done.

classclass Timezone tz where
#

standard representation for timezone

Methods

  • timezoneOffset :: tz -> Int

    offset in minutes from UTC. valid values should be between -12*60 to +14*60

  • timezoneName :: tz -> String

    the name of the timezone. by default will be +-HH:MM encoding.

Instances2Timezone
datadata UTC
#

Universal Time Coordinated. The generic computer "timezone".

Instances4Eq, Ord, Show, Timezone
  • Eq UTCDefined in hourglass-0.2.12 · Data.Hourglass.Zone
  • Ord UTCDefined in hourglass-0.2.12 · Data.Hourglass.Zone
  • Show UTCDefined in hourglass-0.2.12 · Data.Hourglass.Zone
  • Timezone UTCDefined in hourglass-0.2.12 · Data.Hourglass.Zone

Calendar misc functions

4 declarations
valueisLeapYear :: Int -> Bool
#

Return if this year is a leap year (366 days) or not (365 days in a year)

valuegetDayOfTheYear :: Date -> Int
#

return the day of the year where Jan 1 is 0

between 0 and 364. 365 for leap years