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

Modulerebase-1.21.2Haskell2010

Rebase.Data.Time.Compat

  • 16 types
  • 3 classes
  • 86 values
  • Packagerebase-1.21.2
  • Exports120
  • LanguageHaskell2010
  • LicenceMIT
  • SourceLocalTime.hs
datadata LocalTime
#

A simple day and time aggregate, where the day is of the specified parameter, and the time is a TimeOfDay. Conversion of this (as local civil time) to UTC depends on the time zone. Conversion of this (as local mean time) to UT1 depends on the longitude.

Instances12Eq, Data, Ord, Read, Show, Generic, …
datadata CalendarDiffDays
#
Instances12Eq, Data, Show, Generic, Semigroup, Monoid, …
newtypenewtype Day
#

The Modified Julian Day is a standard count of days, with zero being the day 1858-11-17.

Instances16Enum, Eq, Data, Ord, Read, Show, …
  • Enum DayDefined in time-1.12.2 · Data.Time.Calendar.Days
  • Eq DayDefined in time-1.12.2 · Data.Time.Calendar.Days
  • Data DayDefined in time-1.12.2 · Data.Time.Calendar.Days
  • Ord DayDefined in time-1.12.2 · Data.Time.Calendar.Days
  • Read DayDefined in time-1.12.2 · Data.Time.Format.Parse · orphan
  • Show DayDefined in time-1.12.2 · Data.Time.Calendar.Gregorian · orphan
  • Ix DayDefined in time-1.12.2 · Data.Time.Calendar.Days
  • Generic DayDefined in time-compat-1.9.8 · Data.Time.Orphans · orphan
  • NFData DayDefined in time-1.12.2 · Data.Time.Calendar.Days
  • Hashable DayDefined in time-compat-1.9.8 · Data.Time.Orphans · orphan
  • DayPeriod DayDefined in time-1.12.2 · Data.Time.Calendar.Days
  • FormatTime DayDefined in time-1.12.2 · Data.Time.Format.Format.Instances · orphan
  • ParseTime DayDefined in time-1.12.2 · Data.Time.Format.Parse.Instances · orphan
  • ISO8601 DayDefined in time-1.12.2 · Data.Time.Format.ISO8601

    yyyy-mm-dd (ISO 8601:2004(E) sec. 4.1.2.2 extended format)

  • Lift DayDefined in time-compat-1.9.8 · Data.Time.Orphans · orphan
  • type Rep Day = D1 ('MetaData "Day" "Data.Time.Calendar.Days" "time-1.12.2-cfd2" 'True) (C1 ('MetaCons "ModifiedJulianDay" 'PrefixI 'True) (S1 ('MetaSel ('Just "toModifiedJulianDay") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Integer)))Defined in time-compat-1.9.8 · Data.Time.Orphans · orphan
classclass Ord p => DayPeriod p where
#

The class of types which can be represented as a period of days.

Methods

Instances4DayPeriod
valueperiodFromDay :: DayPeriod p => Day -> (p, Int)
#

Get the period this day is in, with the 1-based day number within the period.

periodFromDay (periodFirstDay p) = (p,1)
patternpattern YearMonthDay :: Year -> MonthOfYear -> DayOfMonth -> Day
#

Bidirectional abstract constructor for the proleptic Gregorian calendar. Invalid values will be clipped to the correct range, month first, then day.

Add months, with days past the last day of the month clipped to the last day. For instance, 2005-01-30 + 1 month = 2005-02-28.

Add years, matching month and day, with Feb 29th clipped to Feb 28th if necessary. For instance, 2004-02-29 + 2 years = 2006-02-28.

Add years, matching month and day, with Feb 29th rolled over to Mar 1st if necessary. For instance, 2004-02-29 + 2 years = 2006-03-01.

valueisLeapYear :: Year -> Bool
#

Is this year a leap year according to the proleptic Gregorian calendar?

typetype MonthOfYear = Int
#

Month of year, in range 1 (January) to 12 (December).

typetype Year = Integer
#

Year of Common Era (when positive).

datadata DayOfWeek
#
Instances11Enum, Eq, Data, Ord, Read, Show, …
  • Enum DayOfWeekDefined in time-1.12.2 · Data.Time.Calendar.Week

    "Circular", so for example [Tuesday ..] gives an endless sequence. Also: fromEnum gives [1 .. 7] for [Monday .. Sunday], and toEnum performs mod 7 to give a cycle of days.

  • Eq DayOfWeekDefined in time-1.12.2 · Data.Time.Calendar.Week
  • Data DayOfWeekDefined in time-1.12.2 · Data.Time.Calendar.Week
  • Ord DayOfWeekDefined in time-1.12.2 · Data.Time.Calendar.Week
  • Read DayOfWeekDefined in time-1.12.2 · Data.Time.Calendar.Week
  • Show DayOfWeekDefined in time-1.12.2 · Data.Time.Calendar.Week
  • Ix DayOfWeekDefined in time-1.12.2 · Data.Time.Calendar.Week
  • NFData DayOfWeekDefined in time-1.12.2 · Data.Time.Calendar.Week
  • Hashable DayOfWeekDefined in time-compat-1.9.8 · Data.Time.Orphans · orphan
  • FormatTime DayOfWeekDefined in time-1.12.2 · Data.Time.Format.Format.Instances · orphan
  • Lift DayOfWeekDefined in time-compat-1.9.8 · Data.Time.Orphans · orphan
valueweekAllDays :: DayOfWeek -> Day -> [Day]
#

Returns a week containing the given Day where the first day is the DayOfWeek specified.

Examples:

Example1 expression
weekAllDays Sunday (YearMonthDay 2022 02 21)[YearMonthDay 2022 2 20 .. YearMonthDay 2022 2 26]
Example1 expression
weekAllDays Monday (YearMonthDay 2022 02 21)[YearMonthDay 2022 2 21 .. YearMonthDay 2022 2 27]
Example1 expression
weekAllDays Tuesday (YearMonthDay 2022 02 21)[YearMonthDay 2022 2 15 .. YearMonthDay 2022 2 21]
valueweekFirstDay :: DayOfWeek -> Day -> Day
#

Returns the first day of a week containing the given Day.

Examples:

Example1 expression
weekFirstDay Sunday (YearMonthDay 2022 02 21)YearMonthDay 2022 2 20
Example1 expression
weekFirstDay Monday (YearMonthDay 2022 02 21)YearMonthDay 2022 2 21
Example1 expression
weekFirstDay Tuesday (YearMonthDay 2022 02 21)YearMonthDay 2022 2 15
valueweekLastDay :: DayOfWeek -> Day -> Day
#

Returns the last day of a week containing the given Day.

Examples:

Example1 expression
weekLastDay Sunday (YearMonthDay 2022 02 21)YearMonthDay 2022 2 26
Example1 expression
weekLastDay Monday (YearMonthDay 2022 02 21)YearMonthDay 2022 2 27
Example1 expression
weekLastDay Tuesday (YearMonthDay 2022 02 21)YearMonthDay 2022 2 21
newtypenewtype DiffTime
#

This is a length of time, as measured by a clock. Conversion functions such as fromInteger and realToFrac will treat it as seconds. For example, (0.010 :: DiffTime) corresponds to 10 milliseconds.

It has a precision of one picosecond (= 10^-12 s). Enumeration functions will treat it as picoseconds.

Instances15Enum, Eq, Fractional, Data, Num, Ord, …
  • Enum DiffTimeDefined in time-1.12.2 · Data.Time.Clock.Internal.DiffTime
  • Eq DiffTimeDefined in time-1.12.2 · Data.Time.Clock.Internal.DiffTime
  • Fractional DiffTimeDefined in time-1.12.2 · Data.Time.Clock.Internal.DiffTime
  • Data DiffTimeDefined in time-1.12.2 · Data.Time.Clock.Internal.DiffTime
  • Num DiffTimeDefined in time-1.12.2 · Data.Time.Clock.Internal.DiffTime
  • Ord DiffTimeDefined in time-1.12.2 · Data.Time.Clock.Internal.DiffTime
  • Read DiffTimeDefined in time-1.12.2 · Data.Time.Clock.Internal.DiffTime
  • Real DiffTimeDefined in time-1.12.2 · Data.Time.Clock.Internal.DiffTime
  • RealFrac DiffTimeDefined in time-1.12.2 · Data.Time.Clock.Internal.DiffTime
  • Show DiffTimeDefined in time-1.12.2 · Data.Time.Clock.Internal.DiffTime
  • NFData DiffTimeDefined in time-1.12.2 · Data.Time.Clock.Internal.DiffTime
  • Hashable DiffTimeDefined in time-compat-1.9.8 · Data.Time.Orphans · orphan
  • FormatTime DiffTimeDefined in time-1.12.2 · Data.Time.Format.Format.Instances · orphan
  • ParseTime DiffTimeDefined in time-1.12.2 · Data.Time.Format.Parse.Instances · orphan
  • Lift DiffTimeDefined in time-compat-1.9.8 · Data.Time.Orphans · orphan
newtypenewtype NominalDiffTime
#

This is a length of time, as measured by UTC. It has a precision of 10^-12 s.

Conversion functions such as fromInteger and realToFrac will treat it as seconds. For example, (0.010 :: NominalDiffTime) corresponds to 10 milliseconds.

It has a precision of one picosecond (= 10^-12 s). Enumeration functions will treat it as picoseconds.

It ignores leap-seconds, so it's not necessarily a fixed amount of clock time. For instance, 23:00 UTC + 2 hours of NominalDiffTime = 01:00 UTC (+ 1 day), regardless of whether a leap-second intervened.

Instances15Enum, Eq, Fractional, Data, Num, Ord, …
datadata UTCTime
#

This is the simplest representation of UTC. It consists of the day number, and a time offset from midnight. Note that if a day has a leap second added to it, it will have 86401 seconds.

Constructors

Instances13Eq, Data, Ord, Read, Show, Generic, …
newtypenewtype UniversalTime
#

The Modified Julian Date is the day with the fraction of the day, measured from UT midnight. It's used to represent UT1, which is time as measured by the earth's rotation, adjusted for various wobbles.

Instances12Eq, Data, Ord, Read, Show, Generic, …
classclass FormatTime t where
#
Instances13FormatTime, …
valueformatTime :: FormatTime t => TimeLocale -> String -> t -> String
#

Substitute various time-related information for each %-code in the string, as per formatCharacter.

The general form is %<modifier><width><alternate><specifier>, where <modifier>, <width>, and <alternate> are optional.

<modifier>

glibc-style modifiers can be used before the specifier (here marked as z):

%-z

no padding

%_z

pad with spaces

%0z

pad with zeros

%^z

convert to upper case

%#z

convert to lower case (consistently, unlike glibc)

<width>

Width digits can also be used after any modifiers and before the specifier (here marked as z), for example:

%4z

pad to 4 characters (with default padding character)

%_12z

pad with spaces to 12 characters

<alternate>

An optional E character indicates an alternate formatting. Currently this only affects %Z and %z.

%Ez

alternate formatting

<specifier>

For all types (note these three are done by formatTime, not by formatCharacter):

%%

%

%t

tab

%n

newline

TimeZone

For TimeZone (and ZonedTime and UTCTime):

%z

timezone offset in the format

±HHMM

%Ez

timezone offset in the format

±HH:MM

%Z

timezone name (or else offset in the format

±HHMM

)

%EZ

timezone name (or else offset in the format

±HH:MM

)

LocalTime

For LocalTime (and ZonedTime and UTCTime and UniversalTime):

%c

as

dateTimeFmt

locale

(e.g.

%a %b %e %H:%M:%S %Z %Y

)

TimeOfDay

For TimeOfDay (and LocalTime and ZonedTime and UTCTime and UniversalTime):

%R

same as

%H:%M

%T

same as

%H:%M:%S

%X

as

timeFmt

locale

(e.g.

%H:%M:%S

)

%r

as

time12Fmt

locale

(e.g.

%I:%M:%S %p

)

%P

day-half of day from (

amPm

locale

), converted to lowercase,

am

,

pm

%p

day-half of day from (

amPm

locale

),

AM

,

PM

%H

hour of day (24-hour), 0-padded to two chars,

00

-

23

%k

hour of day (24-hour), space-padded to two chars,

0

-

23

%I

hour of day-half (12-hour), 0-padded to two chars,

01

-

12

%l

hour of day-half (12-hour), space-padded to two chars,

1

-

12

%M

minute of hour, 0-padded to two chars,

00

-

59

%S

second of minute (without decimal part), 0-padded to two chars,

00

-

60

%q

picosecond of second, 0-padded to twelve chars,

000000000000

-

999999999999

.

%Q

decimal point and fraction of second, up to 12 second decimals, without trailing zeros. For a whole number of seconds,

%Q

omits the decimal point unless padding is specified.

UTCTime and ZonedTime

For UTCTime and ZonedTime:

%s

number of whole seconds since the Unix epoch. For times before the Unix epoch, this is a negative number. Note that in

%s.%q

and

%s%Q

the decimals are positive, not negative. For example, 0.9 seconds before the Unix epoch is formatted as

-1.1

with

%s%Q

.

DayOfWeek

For DayOfWeek (and Day and LocalTime and ZonedTime and UTCTime and UniversalTime):

%u

day of week number for Week Date format,

1

(= Monday) -

7

(= Sunday)

%w

day of week number,

0

(= Sunday) -

6

(= Saturday)

%a

day of week, short form (

snd

from

wDays

locale

),

Sun

-

Sat

%A

day of week, long form (

fst

from

wDays

locale

),

Sunday

-

Saturday

Month

For Month (and Day and LocalTime and ZonedTime and UTCTime and UniversalTime):

%Y

year, no padding. Note

%0Y

and

%_Y

pad to four chars

%y

year of century, 0-padded to two chars,

00

-

99

%C

century, no padding. Note

%0C

and

%_C

pad to two chars

%B

month name, long form (

fst

from

months

locale

),

January

-

December

%b, %h

month name, short form (

snd

from

months

locale

),

Jan

-

Dec

%m

month of year, 0-padded to two chars,

01

-

12

Day

For Day (and LocalTime and ZonedTime and UTCTime and UniversalTime):

%D

same as

%m/%d/%y

%F

same as

%Y-%m-%d

%x

as

dateFmt

locale

(e.g.

%m/%d/%y

)

%d

day of month, 0-padded to two chars,

01

-

31

%e

day of month, space-padded to two chars,

1

-

31

%j

day of year, 0-padded to three chars,

001

-

366

%f

century for Week Date format, no padding. Note

%0f

and

%_f

pad to two chars

%V

week of year for Week Date format, 0-padded to two chars,

01

-

53

%U

week of year where weeks start on Sunday (as

sundayStartWeek

), 0-padded to two chars,

00

-

53

%W

week of year where weeks start on Monday (as

mondayStartWeek

), 0-padded to two chars,

00

-

53

Duration types

The specifiers for DiffTime, NominalDiffTime, CalendarDiffDays, and CalendarDiffTime are semantically separate from the other types. Specifiers on negative time differences will generally be negative (think rem rather than mod).

NominalDiffTime and DiffTime

Note that a "minute" of DiffTime is simply 60 SI seconds, rather than a minute of civil time. Use NominalDiffTime to work with civil time, ignoring any leap seconds.

For NominalDiffTime and DiffTime:

%w

total whole weeks

%d

total whole days

%D

whole days of week

%h

total whole hours

%H

whole hours of day

%m

total whole minutes

%M

whole minutes of hour

%s

total whole seconds

%Es

total seconds, with decimal point and up to <width> (default 12) decimal places, without trailing zeros. For a whole number of seconds,

%Es

omits the decimal point unless padding is specified.

%0Es

total seconds, with decimal point and <width> (default 12) decimal places.

%S

whole seconds of minute

%ES

seconds of minute, with decimal point and up to <width> (default 12) decimal places, without trailing zeros. For a whole number of seconds,

%ES

omits the decimal point unless padding is specified.

%0ES

seconds of minute as two digits, with decimal point and <width> (default 12) decimal places.

CalendarDiffDays

For CalendarDiffDays (and CalendarDiffTime):

%y

total years

%b

total months

%B

months of year

%w

total weeks, not including months

%d

total days, not including months

%D

days of week

CalendarDiffTime

For CalendarDiffTime:

%h

total hours, not including months

%H

hours of day

%m

total minutes, not including months

%M

minutes of hour

%s

total whole seconds, not including months

%Es

total seconds, not including months, with decimal point and up to <width> (default 12) decimal places, without trailing zeros. For a whole number of seconds,

%Es

omits the decimal point unless padding is specified.

%0Es

total seconds, not including months, with decimal point and <width> (default 12) decimal places.

%S

whole seconds of minute

%ES

seconds of minute, with decimal point and up to <width> (default 12) decimal places, without trailing zeros. For a whole number of seconds,

%ES

omits the decimal point unless padding is specified.

%0ES

seconds of minute as two digits, with decimal point and <width> (default 12) decimal places.

datadata TimeLocale
#

Constructors

Instances4Eq, Ord, Show, Hashable

Locale representing American usage.

knownTimeZones contains only the ten time-zones mentioned in RFC 822 sec. 5: "UT", "GMT", "EST", "EDT", "CST", "CDT", "MST", "MDT", "PST", "PDT". Note that the parsing functions will regardless parse "UTC", single-letter military time-zones, and +HHMM format.

valueparseTimeM
  1. :: (MonadFail m, ParseTime t)
  2. => Bool

    Accept leading and trailing whitespace?

  3. -> TimeLocale

    Time locale.

  4. -> String

    Format string.

  5. -> String

    Input string.

  6. -> m t

    Return the time value, or fail if the input could not be parsed using the given format.

#

Parses a time value given a format string. Missing information will be derived from 1970-01-01 00:00 UTC (which was a Thursday). Supports the same %-codes as formatTime, including %-, %_ and %0 modifiers, however padding widths are not supported. Case is not significant in the input string. Some variations in the input are accepted:

%z %Ez

accepts any of

±HHMM

or

±HH:MM

.

%Z %EZ

accepts any string of letters, or any of the formats accepted by

%z

.

%0Y

accepts exactly four digits.

%0G

accepts exactly four digits.

%0C

accepts exactly two digits.

%0f

accepts exactly two digits.

For example, to parse a date in YYYY-MM-DD format, while allowing the month and date to have optional leading zeros (notice the - modifier used for %m and %d):

Prelude Data.Time> parseTimeM True defaultTimeLocale "%Y-%-m-%-d" "2010-3-04" :: Maybe Day
Just 2010-03-04
classclass ParseTime t where
#

The class of types which can be parsed given a UNIX-style time format string.

Instances12ParseTime, …
datadata CalendarDiffTime
#
Instances11Eq, Data, Show, Generic, Semigroup, Monoid, …
datadata TimeOfDay
#

Time of day as represented in hour, minute and second (with picoseconds), typically used to express local time of day.

TimeOfDay 24 0 0 is considered invalid for the purposes of makeTimeOfDayValid, as well as reading and parsing, but valid for ISO 8601 parsing in Data.Time.Format.ISO8601.

Constructors

  • TimeOfDay
    • todHour :: Int

      range 0 - 23

    • todMin :: Int

      range 0 - 59

    • todSec :: Pico

      Note that 0 <= todSec < 61, accomodating leap seconds. Any local minute may have a leap second, since leap seconds happen in all zones simultaneously

Instances12Eq, Data, Ord, Read, Show, Generic, …
datadata TimeZone
#

A TimeZone is a whole number of minutes offset from UTC, together with a name and a "just for summer" flag.

Constructors

Instances12Eq, Data, Ord, Read, Show, Generic, …

Get the configured time-zone for a given time (varying as per summertime adjustments).

On Unix systems the output of this function depends on:

  1. The value of TZ environment variable (if set)

  2. The system time zone (usually configured by /etc/localtime symlink)

For details see tzset(3) and localtime(3).

Example:

> let t = UTCTime (fromGregorian 2021 7 1) 0
> getTimeZone t
CEST
> setEnv "TZ" "America/New_York" >> getTimeZone t
EDT
> setEnv "TZ" "Europe/Berlin" >> getTimeZone t
CEST

On Windows systems the output of this function depends on:

  1. The value of TZ environment variable (if set). See here for how Windows interprets this variable.

  2. The system time zone, configured in Settings

datadata ZonedTime
#

A local time together with a time zone.

There is no Eq instance for ZonedTime. If you want to compare local times, use zonedTimeToLocalTime. If you want to compare absolute times, use zonedTimeToUTC.

Instances9Data, Read, Show, Generic, NFData, FormatTime, …