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

GHC 9.14.1 · lts/ghc-9.14.x · 3e2d568 · 2026-10-11

Moduletime-hourglass-0.3.0Haskell2010

Data.Hourglass

Time-related types and functions.

Basic types for representing points in time are Elapsed and ElapsedP. The 'P' is short for 'precise'. Elapsed represents numbers of non-leap seconds elapsed since the Unix epoch (that is, the point of time represented by 1970-01-01 00:00:00 UTC). ElapsedP represents numbers of non-leap seconds and nanoseconds elapsed since that point in time.

Values of other types representing points in time can be converted to and from values of the Elapsed and ElapsedP types. For example:

d = timeGetElapsed (Date 1955 April 18) :: Elapsed
timeFromElapsed d :: DateTime

Local time is represented by LocalTime t, parameterised by any other type representing time (for example, Elapsed, Date or DateTime). A local time value is augmented by a timezone offset in minutes. For example:

localTime (Date 2014 May 4) 600 -- local time at UTC+10 of 4th May 2014
  • 22 types
  • 5 classes
  • 30 values

Time units

4 declarations
newtypenewtype NanoSeconds
#

Type representing numbers of nanoseconds.

Constructors

Instances8Eq, Data, Num, Ord, Read, Show, …
newtypenewtype Seconds
#

Type representing numbers of seconds (non-leap or all).

Constructors

Instances11Enum, Eq, Integral, Data, Num, Ord, …
  • Enum SecondsDefined in time-hourglass-0.3.0 · Time.Types
  • Eq SecondsDefined in time-hourglass-0.3.0 · Time.Types
  • Integral SecondsDefined in time-hourglass-0.3.0 · Time.Types
  • Data SecondsDefined in time-hourglass-0.3.0 · Time.Types
  • Num SecondsDefined in time-hourglass-0.3.0 · Time.Types
  • Ord SecondsDefined in time-hourglass-0.3.0 · Time.Types
  • Read SecondsDefined in time-hourglass-0.3.0 · Time.Types
  • Real SecondsDefined in time-hourglass-0.3.0 · Time.Types
  • Show SecondsDefined in time-hourglass-0.3.0 · Time.Types

    Show the number of seconds followed by s. (Note: the Read instance is derived.)

  • NFData SecondsDefined in time-hourglass-0.3.0 · Time.Types
  • TimeInterval SecondsDefined in time-hourglass-0.3.0 · Time.Types
newtypenewtype Minutes
#

Type representing numbers of minutes.

Constructors

Instances11Enum, Eq, Integral, Data, Num, Ord, …
  • Enum MinutesDefined in time-hourglass-0.3.0 · Time.Types
  • Eq MinutesDefined in time-hourglass-0.3.0 · Time.Types
  • Integral MinutesDefined in time-hourglass-0.3.0 · Time.Types
  • Data MinutesDefined in time-hourglass-0.3.0 · Time.Types
  • Num MinutesDefined in time-hourglass-0.3.0 · Time.Types
  • Ord MinutesDefined in time-hourglass-0.3.0 · Time.Types
  • Read MinutesDefined in time-hourglass-0.3.0 · Time.Types
  • Real MinutesDefined in time-hourglass-0.3.0 · Time.Types
  • Show MinutesDefined in time-hourglass-0.3.0 · Time.Types

    Show the number of minutes followed by m. (Note: the Read instance is derived.)

  • NFData MinutesDefined in time-hourglass-0.3.0 · Time.Types
  • TimeInterval MinutesDefined in time-hourglass-0.3.0 · Time.Types
newtypenewtype Hours
#

Type representing numbers of hours.

Constructors

Instances11Enum, Eq, Integral, Data, Num, Ord, …
  • Enum HoursDefined in time-hourglass-0.3.0 · Time.Types
  • Eq HoursDefined in time-hourglass-0.3.0 · Time.Types
  • Integral HoursDefined in time-hourglass-0.3.0 · Time.Types
  • Data HoursDefined in time-hourglass-0.3.0 · Time.Types
  • Num HoursDefined in time-hourglass-0.3.0 · Time.Types
  • Ord HoursDefined in time-hourglass-0.3.0 · Time.Types
  • Read HoursDefined in time-hourglass-0.3.0 · Time.Types
  • Real HoursDefined in time-hourglass-0.3.0 · Time.Types
  • Show HoursDefined in time-hourglass-0.3.0 · Time.Types

    Show the number of hours followed by h. (Note: the Read instance is derived.)

  • NFData HoursDefined in time-hourglass-0.3.0 · Time.Types
  • TimeInterval HoursDefined in time-hourglass-0.3.0 · Time.Types

Calendar enumerations

2 declarations
datadata Month
#

Type representing months of the Julian or Gregorian year.

Instances7Bounded, Enum, Eq, Data, Ord, Read, …
  • Bounded MonthDefined in time-hourglass-0.3.0 · Time.Types
  • Enum MonthDefined in time-hourglass-0.3.0 · Time.Types
  • Eq MonthDefined in time-hourglass-0.3.0 · Time.Types
  • Data MonthDefined in time-hourglass-0.3.0 · Time.Types
  • Ord MonthDefined in time-hourglass-0.3.0 · Time.Types
  • Read MonthDefined in time-hourglass-0.3.0 · Time.Types
  • Show MonthDefined in time-hourglass-0.3.0 · Time.Types
datadata WeekDay
#

Type representing days of the week. The enumeration starts on Sunday.

Instances7Bounded, Enum, Eq, Data, Ord, Read, …
  • Bounded WeekDayDefined in time-hourglass-0.3.0 · Time.Types
  • Enum WeekDayDefined in time-hourglass-0.3.0 · Time.Types
  • Eq WeekDayDefined in time-hourglass-0.3.0 · Time.Types
  • Data WeekDayDefined in time-hourglass-0.3.0 · Time.Types
  • Ord WeekDayDefined in time-hourglass-0.3.0 · Time.Types
  • Read WeekDayDefined in time-hourglass-0.3.0 · Time.Types
  • Show WeekDayDefined in time-hourglass-0.3.0 · Time.Types

Points in time

0 declarations

Precise amounts of seconds

Elapsed time since the Unix epoch

newtypenewtype Elapsed
#

Type representing numbers of non-leap seconds elapsed since the Unix epoch (1970-01-01 00:00:00 UTC).

Points in time before the Unix epoch are represented by a negative number of seconds.

Constructors

Instances9Eq, Data, Num, Ord, Read, Show, …
  • Eq ElapsedDefined in time-hourglass-0.3.0 · Time.Types
  • Data ElapsedDefined in time-hourglass-0.3.0 · Time.Types
  • Num ElapsedDefined in time-hourglass-0.3.0 · Time.Types
  • Ord ElapsedDefined in time-hourglass-0.3.0 · Time.Types
  • Read ElapsedDefined in time-hourglass-0.3.0 · Time.Types
  • Show ElapsedDefined in time-hourglass-0.3.0 · Time.Types

    Show the number of seconds followed by s. (Note: the Read instance is derived.)

  • NFData ElapsedDefined in time-hourglass-0.3.0 · Time.Types
  • Time ElapsedDefined in time-hourglass-0.3.0 · Time.Time
  • Timeable ElapsedDefined in time-hourglass-0.3.0 · Time.Time
datadata ElapsedP
#

Type representing numbers of non-leap seconds and nanoseconds elapsed since the Unix epoch (1970-01-01 00:00:00 UTC).

Constructors

Instances10Eq, Data, Num, Ord, Read, Real, …
  • Eq ElapsedPDefined in time-hourglass-0.3.0 · Time.Types
  • Data ElapsedPDefined in time-hourglass-0.3.0 · Time.Types
  • Num ElapsedPDefined in time-hourglass-0.3.0 · Time.Types
  • Ord ElapsedPDefined in time-hourglass-0.3.0 · Time.Types
  • Read ElapsedPDefined in time-hourglass-0.3.0 · Time.Types
  • Real ElapsedPDefined in time-hourglass-0.3.0 · Time.Types
  • Show ElapsedPDefined in time-hourglass-0.3.0 · Time.Types

    Show the number of seconds followed by s, ., and the number of nanoseconds followed by ns. (Note: the Read instance is derived.)

  • NFData ElapsedPDefined in time-hourglass-0.3.0 · Time.Types
  • Time ElapsedPDefined in time-hourglass-0.3.0 · Time.Time
  • Timeable ElapsedPDefined in time-hourglass-0.3.0 · Time.Time

Given a precise amount of non-leap seconds elapsed since the Unix epoch, yield the corresponding ElapsedP value.

The ElapsedP value will be normalised. That is, the nanoseconds field will be non-negative and fewer than 1,000,000,000 nanoseconds (being 1 second).

Date, time, and date and time

datadata Date
#

Type representing dates in the proleptic Gregorian calendar (the common calendar).

Constructors

Instances8Eq, Data, Ord, Read, Show, NFData, …
  • Eq DateDefined in time-hourglass-0.3.0 · Time.Types
  • Data DateDefined in time-hourglass-0.3.0 · Time.Types
  • Ord DateDefined in time-hourglass-0.3.0 · Time.Types
  • Read DateDefined in time-hourglass-0.3.0 · Time.Types
  • Show DateDefined in time-hourglass-0.3.0 · Time.Types
  • NFData DateDefined in time-hourglass-0.3.0 · Time.Types
  • Time DateDefined in time-hourglass-0.3.0 · Time.Time
  • Timeable DateDefined in time-hourglass-0.3.0 · Time.Time
datadata TimeOfDay
#

Type representing times as hour, minutes, seconds and nanoseconds.

Constructors

Instances6Eq, Data, Ord, Read, Show, NFData
datadata DateTime
#

Type representing date and time.

Instances8Eq, Data, Ord, Read, Show, NFData, …

Local time and timezone-related

datadata LocalTime t
#

Type representing local times.

Instances5Functor, Eq, Ord, Read, Show
classclass Timezone tz where
#

A type class promising timezone-related functionality.

Methods

  • timezoneOffset :: tz -> Int

    Offset in minutes from UTC. Valid values should be between -12 * 60 and +14 * 60.

  • timezoneName :: tz -> String

    The name of the timezone.

    The default implementation is an ±HH:MM encoding of the timezoneOffset, with an offset of 0 encoded as -00:00.

Instances2Timezone
newtypenewtype TimezoneOffset
#

Type representing offsets in minutes against UTC to obtain local time from UTC. A positive number represents a location east of where UTC is local time and a negative number represents a location west of where UTC is local time.

LocalTime t (-300) -- t represents a time at UTC-5

LocalTime t (+480) -- t represents a time at UTC+8

Should be between (-12 * 60) and (+14 * 60).

For example, in timezone AEDT (Australian Eastern Daylight Time) (UTC+11), local time is 15:47. Consequently, UTC time is 04:47 and the timezone offset is TimezoneOffset 660 (in minutes).

Constructors

Instances6Eq, Data, Ord, Read, Show, NFData
datadata UTC
#

Type representing Universal Time Coordinated (UTC).

Instances4Eq, Ord, Show, Timezone
  • Eq UTCDefined in time-hourglass-0.3.0 · Time.Timezone
  • Ord UTCDefined in time-hourglass-0.3.0 · Time.Timezone
  • Show UTCDefined in time-hourglass-0.3.0 · Time.Timezone
  • Timezone UTCDefined in time-hourglass-0.3.0 · Time.Timezone

Constructors

valuelocalTime
  1. :: Time t
  2. => TimezoneOffset
  3. -> t

    The local time.

  4. -> LocalTime t
#

For the given timezone offset and time value (assumed to be the local time), yield the corresponding local time.

Accessors

Miscellaneous calandar functions

valueisLeapYear
  1. :: Int

    Year.

  2. -> Bool
#

For the given year in the Gregorian calendar, is it a leap year (366 days long)?

valuegetWeekDay :: Date -> WeekDay
#

For the given date in the proleptic Gregorian calendar, yield the day of the week it falls on.

valuegetDayOfTheYear :: Date -> Int
#

For the given date in the proleptic Gregorian calendar, yield the number of days before the date in the same year. For example, there are 0 days before 1st January.

valuedaysInMonth
  1. :: Int

    Year.

  2. -> Month
  3. -> Int
#

For the given year and month in the proleptic Gregorian calendar, yield the number of days in the month.

Periods of time

6 declarations
datadata Duration
#

Type represeting periods of time in hours, minutes, seconds (non-leap or all) and nanoseconds. See Period for periods of time in years, months and days.

Constructors

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

Type representing periods of time in years, months and days. See Duration for periods of time in hours, minutes, seconds (non-leap or all) and nanoseconds.

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

Add the given period of time to the given value for a point in time, assuming that the period of time is equated with a number of non-leap seconds.

Example:

t1 `timeAdd` mempty { durationHours = 12 }

Example:

Example8 expressions
startDate = Date 2016 December 31 -- Date of last leap secondpreLeapSecond = TimeOfDay 23 59 59 0startDateTime = DateTime startDate preLeapSecondoneNonleapSecond = Duration 0 0 1 0 -- Assume non-leap secondsnextDate = Date 2017 January 1firstSecond = TimeOfDay 0 0 0 0endDateTime = DateTime nextDate firstSecondtimeAdd startDateTime oneNonleapSecond == endDateTimeTrue
valuetimeDiff :: (Timeable t1, Timeable t2) => t1 -> t2 -> Seconds
#

For the two given points in time, yields the difference in non-leap seconds between them.

Effectively:

t2 `timeDiff` t1 = t2 - t1
valuetimeDiffP
  1. :: (Timeable t1, Timeable t2)
  2. => t1
  3. -> t2
  4. -> (Seconds, NanoSeconds)
#

For the two given points in time, yields the difference in non-leap seconds and nanoseconds between them.

Effectively:

@t2 `timeDiffP` t1 = t2 - t1

Conversion of points in time

8 declarations
classclass Timeable t => Time t where
#

A type class promising functionality for converting ElapsedP values and Elapsed values to values of the type in question.

Methods

Instances7Time, …
classclass Timeable t where
#

A type class promising functionality for:

  • converting a value of the type in question to a Elapsed value or a ElapsedP value; and

  • yielding separately a nanoseconds component of the value of the type in question (should yield 0 when the type is less precise than seconds).

Methods

  • timeGetElapsedP :: t -> ElapsedP

    Convert the given value to the number of non-leap seconds and nanoseconds elapsed since the Unix epoch (1970-01-01 00:00:00 UTC).

  • timeGetElapsed :: t -> Elapsed

    Convert the given value to the number of non-leap seconds elapsed since the Unix epoch (1970-01-01 00:00:00 UTC).

    Defaults to timeGetElapsedP.

  • timeGetNanoSeconds :: t -> NanoSeconds

    Optionally, for the given value, yield the number of nanoseconds component.

    If the type in question does not provide sub-second precision, should yield 0.

    Defaults to timeGetElapsedP. For efficiency, if the type in question does not provide sub-second precision, it is a good idea to override this method.

Instances7Timeable, …
valuelocalTimeConvert :: (Time t1, Time t2) => LocalTime t1 -> LocalTime t2
#

For the given local time of one type, yield the corresponding local time of a different type. This will not compile unless the compiler can infer the types of the two local times.

Conversion of periods of time

1 declaration
classclass TimeInterval i where
#

Type class promising functionality for:

  • converting a value of the type in question to a number of seconds; and

  • converting a Seconds value to a pair of a value of the type in question and a remaining number of seconds.

Methods

  • toSeconds :: i -> Seconds

    For the given value, yield a corresponding number of seconds (non-leap or all).

  • fromSeconds :: Seconds -> (i, Seconds)

    For the given number of seconds (non-leap or all), yield a pair of the corresponding value of the type in queston and a remaining number of seconds.

Instances5TimeInterval

Parsing and Printing

0 declarations

Format strings

classclass TimeFormat format where
#

A type class promising the ability to convert values to a TimeFormatString.

String is an instance of TimeFormat. Sequences of characters are interpreted as follows (case-sensitive). The longest valid sequence is parsed first:

YY

Format_Year2

. 2-digit years (

70

is 1970,

69

is 2069).

YYYY

Format_Year4

. 4-digit years.

M

Format_Month

. Months (

1

to

12

).

MM

Format_Month2

. Months padded to 2 characters (

01

to

12

).

Mon

Format_MonthName_Short

. Short name of the month (

Jan

,

Feb

, ..).

JJJ

Format_DayYear3

. Day of the year padded to 3 characters (

001

to

365

,

366

for leap years).

DD

Format_Day2

. Day of the month padded to 2 characters (

01

to

31

).

H

Format_Hour

. Hours padded to 2 characters (

00

to

23

).

MI

Format_Minute

. Minutes padded to 2 characters (

00

to

59

).

S

Format_Second

. Seconds padded to 2 characters (

00

to

59

,

60

for leap seconds).

EPOCH

Format_UnixSecond

. Number of non-leap seconds since the Unix epoch (1970-01-01 00:00:00 UTC).

ms

Format_MilliSecond

. The millisecond component only, padded to 3 characters (

000

to

999

). See

us

/

μ

and

ns

for other named sub-second components.

us

Format_MicroSecond

. The microseconds component only, padded to 3 characters (

000

to

999

). See

ms

and

ns

for other named sub-second components.

μ

Format_MicroSecond

. As above.

ns

Format_NanoSecond

. The nanoseconds component only, padded to 3 characters (

000

to

999

). See

ms

and

us

/

μ

for other named sub-second components.

p<n>

Format_Precision

<n>

. Sub-second display with a precision of

<n>

digit(s), where

<n>

is

1

to

9

.

TZH:M

Format_TzHM_Colon

. Timezone offset with colon (for example,

02:00

,

+02:00

or

-02:00

).

TZHM

Format_TzHM

. Timezone offset without colon (for example,

0200

,

+0200

or

-0200

).

TZOFS

Format_Tz_Offset

. Timezone offset in minutes (for example,

120

,

+120

or

-120

).

<space>

Format_Spaces

. One or more space-like characters.

\<character>

Format_Text

<character>

. A verbatim character.

<character>

Format_Text

<character>

. A verbatim character.

For example:

Example2 expressions
let mDateTime = timeParse ("ms \\ms us \\us ns \\ns") "123 ms 456 us 789 ns"timeGetNanoSeconds <$> mDateTimeJust 123456789ns
Example1 expression
timePrint "ms \\ms us \\us ns \\ns" <$> mDateTimeJust "123 ms 456 us 789 ns"

Methods

Instances5TimeFormat
datadata TimeFormatElem
#

Type representing formatters that can be part of a time format string.

Constructors

Instances3Eq, Show, TimeFormat
datadata TimeFormatFct
#

Type representing format functions.

Constructors

Instances2Eq, Show

Common built-in formats

Format methods

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

    The format to use for printing.

  3. -> LocalTime t

    The local time to print.

  4. -> String
#

Given the specified format, pretty print the given local time.

A Format_TimezoneName will print using the ±HH:MM format, where 0 offset is printed as -00:00.

A Format_TzHM will print using the ±HHMM format, where 0 offset is printed as +0000.

A Format_TzHM_Colon will print using the ±HH:MM format, where 0 offset is printed as +00:00.

A Format_TzHM_Colon_Z will print using the ±HH:MM format, but where 0 offset is printed as Z.

A Format_Tz_Offset will print non-negative offsets without using an initial +.

A Format_Spaces will print a single space character.

valuelocalTimeParseE
  1. :: TimeFormat format
  2. => format

    The format to use for parsing.

  3. -> String

    The string to parse.

  4. -> Either (TimeFormatElem, String) (LocalTime DateTime, String)
#

Given the specified format, try to parse the given string as a LocalTime DateTime value.

On failure, yields a Left value with a pair of the current TimeFormatElem value and the reason for the failure.

If successful, yields a Right value with a pair of the parsed value and the remaining unparsed string.

The default parsed LocalTime DateTime value is 'all zeros'. For example:

Example4 expressions
let zeroDate = Date 0 January 0let zeroTime = TimeOfDay 0 0 0 0let zeroLocalTime = localTime timezone_UTC (DateTime zeroDate zeroTime)localTimeParseE "" "" == Right (zeroLocalTime, "")True

Later TimeFormatElem values can modify the result of earlier TimeFormatElem values. For example:

Example2 expressions
let toYear = dateYear . dtDate . localTimeUnwrap . fsttoYear <$> (localTimeParseE "YYYY YYYY" "2025 2024")Right 2024

A Format_DayYear or Format_DayYear3 value interprets the day of year based on the previously parsed year or, by default, a leap year. For example:

Example5 expressions
let toMonth = dateMonth . dtDate . localTimeUnwrap . fstlet format1 = [Format_Year4, Format_Spaces, Format_DayYear]let format2 = [Format_DayYear, Format_Spaces, Format_Year4]toMonth <$> (localTimeParseE format1 "2025 60")Right MarchtoMonth <$> (localTimeParseE format2 "60 2025")Right February

A Format_TimezoneName will parse one or more non-white space characters but will not modify the previously parsed, or default, date and time.

A Format_Month, Format_DayYear, Format_DayYear3, Format_Day and Format_Tz_Offset will check that the parsed number is within bounds. However, localTimeParseE does not check that any resulting date or time is a valid one.