HORIZON HASKELLDocslts/ghc-10.0.x8fef28d2026-11-02Search packagesCtrl K
Theme: |

GHC 10.0.0.20260917 · lts/ghc-10.0.x · 8fef28d · 2026-11-02

Modulechronos-1.1.7.0Haskell2010

Chronos

Chronos is a performance-oriented time library for Haskell, with a straightforward API. The main differences between this and the time library are:

  • Chronos uses machine integers where possible. This means that time-related arithmetic should be faster, with the drawback that the types are incapable of representing times that are very far in the future or the past (because Chronos provides nanosecond, rather than picosecond, resolution). For most users, this is not a hindrance.

  • Chronos provides ToJSON/FromJSON instances for serialisation.

  • Chronos provides Unbox instances for working with unboxed vectors.

  • Chronos provides Prim instances for working with byte arrays/primitive arrays.

  • Chronos uses normal non-overloaded haskell functions for encoding and decoding time. It provides attoparsec parsers for both Text and ByteString. Additionally, Chronos provides functions for encoding time to Text or ByteString. The time library accomplishes these with the Data.Time.Format module, which uses UNIX-style datetime format strings. The approach taken by Chronos is faster and catches more mistakes at compile time, at the cost of being less expressive.

Contents
  1. Functions
  2. Current
  3. Duration
  4. Construction
  5. Conversion
  6. Build Timespan
  7. Matching
  8. Format
  9. Months
  10. Days of Week
  11. Utility
  12. Textual Conversion
  13. Date
  14. Text
  15. UTF-8 ByteString
  16. Time of Day
  17. Text
  18. UTF-8 ByteString
  19. Datetime
  20. Text
  21. UTF-8 ByteString
  22. UTF-8 Bytes
  23. Short Text
  24. Offset Datetime
  25. Text
  26. UTF-8 ByteString
  27. UTF-8 Bytes
  28. ShortText
  29. Offset
  30. Text
  31. UTF-8 ByteString
  32. Timespan
  33. Text
  34. UTF-8 ByteString
  35. TimeInterval
  36. Types
  37. Lenses
Synopsis
  • Packagechronos-1.1.7.0
  • Exports238
  • LanguageHaskell2010
  • LicenceBSD-3-Clause
  • SourceChronos.hs

Functions

Current

valuetoday :: IO Day

Gets the current Day. This does not take the user's time zone into account.

Duration

valuestopwatch :: IO a -> IO (Timespan, a)

Measures the time it takes to run an action and evaluate its result to WHNF. This measurement uses a monotonic clock instead of the standard system clock.

valuestopwatch_ :: IO a -> IO Timespan

Measures the time it takes to run an action. The result is discarded. This measurement uses a monotonic clock instead of the standard system clock.

Construction

valuedatetimeFromYmdhms
  1. :: Int

    Year

  2. -> Int

    Month

  3. -> Int

    Day

  4. -> Int

    Hour

  5. -> Int

    Minute

  6. -> Int

    Second

  7. -> Datetime

Construct a Datetime from year, month, day, hour, minute, second:

Example1 expression
datetimeFromYmdhms 2014 2 26 17 58 52Datetime {datetimeDate = Date {dateYear = Year {getYear = 2014}, dateMonth = Month {getMonth = 1}, dateDay = DayOfMonth {getDayOfMonth = 26}}, datetimeTime = TimeOfDay {timeOfDayHour = 17, timeOfDayMinute = 58, timeOfDayNanoseconds = 52000000000}}
valuetimeFromYmdhms
  1. :: Int

    Year

  2. -> Int

    Month

  3. -> Int

    Day

  4. -> Int

    Hour

  5. -> Int

    Minute

  6. -> Int

    Second

  7. -> Time

Construct a Time from year, month, day, hour, minute, second:

Example1 expression
timeFromYmdhms 2014 2 26 17 58 52Time {getTime = 1393437532000000000}

Conversion

Build Timespan

Matching

Format

The formats provided is this module are language-agnostic. To find meridiem formats and month formats, look in a language-specific module.

The W3C DatetimeFormat.

Example1 expression
encode_YmdHMS SubsecondPrecisionAuto w3c (timeToDatetime (timeFromYmdhms 2014 2 26 17 58 52))"2014-02-26T17:58:52"
Property
\(s :: SubsecondPrecision) (dt :: Datetime) -> isJust (decode_YmdHMS w3c (encode_YmdHMS s w3c dt))

A DatetimeFormat that separates the members of the Date by slashes.

Example1 expression
encode_YmdHMS SubsecondPrecisionAuto slash (timeToDatetime (timeFromYmdhms 2014 2 26 17 58 52))"2014/02/26 17:58:52"
Property
\(s :: SubsecondPrecision) (dt :: Datetime) -> isJust (decode_YmdHMS slash (encode_YmdHMS s slash dt))

A DatetimeFormat that separates the members of the Date by hyphens.

Example1 expression
encode_YmdHMS SubsecondPrecisionAuto hyphen (timeToDatetime (timeFromYmdhms 2014 2 26 17 58 52))"2014-02-26 17:58:52"
Property
\(s :: SubsecondPrecision) (dt :: Datetime) -> isJust (decode_YmdHMS hyphen (encode_YmdHMS s hyphen dt))

A DatetimeFormat with no separators, except for a T between the Date and Time.

Example1 expression
encode_YmdHMS SubsecondPrecisionAuto compact (timeToDatetime (timeFromYmdhms 2014 2 26 17 58 52))"20140226T175852"
Property
\(s :: SubsecondPrecision) (dt :: Datetime) -> isJust (decode_YmdHMS compact (encode_YmdHMS s compact dt))

Months

Days of Week

Utility

valueisLeapYear :: Year -> Bool

Is the Year a leap year?

Example1 expression
isLeapYear (Year 1996)True
Example1 expression
isLeapYear (Year 2019)False

Textual Conversion

Date

Text

UTF-8 ByteString

Time of Day

Text

Parses text that is formatted as either of the following:

  • %H:%M
  • %H:%M:%S

That is, the seconds and subseconds part is optional. If it is not provided, it is assumed to be zero. This format shows up in Google Chrome's datetime-local inputs.

UTF-8 ByteString

Parses text that is formatted as either of the following:

  • %H:%M
  • %H:%M:%S

That is, the seconds and subseconds part is optional. If it is not provided, it is assumed to be zero. This format shows up in Google Chrome's datetime-local inputs.

Datetime

Text

Construct Text corresponding to the ISO-8601 encoding of the given Datetime.

Example1 expression
encodeIso8601 (datetimeFromYmdhms 2014 2 26 17 58 52)"2014-02-26T17:58:52"
valueencode_Ymd :: Maybe Char -> Date -> Text

Given a Date and a separator, construct a Text corresponding to a Year/Month/Day encoding.

Example1 expression
encode_Ymd (Just ':') (Date (Year 2022) january (DayOfMonth 13))"2022:01:13"
valueencode_Dmy :: Maybe Char -> Date -> Text

Given a Date and a separator, construct a Text corresponding to a Day/Month/Year encoding.

Example1 expression
encode_Dmy (Just ':') (Date (Year 2022) january (DayOfMonth 13))"13:01:2022"

Parse a Day/Month/Year,Hour/Minute/Second-encoded Datetime from Text that was encoded with either no separators or any non-numeric character for each separator, such as:

01-05-2017T23:13:05 01-05-2017 23:13:05 01052017 23:13:05 01y01/2018x23;50&29

Parses a Year/Month/Date,Hour/Minute/Second-encoded Datetime from Text that was encoded with the given DatetimeFormat and with either of the following time formats:

  • %H:%M
  • %H:%M:%S

That is, the seconds and subseconds part is optional. If it is not provided, it is assumed to be zero. This format shows up in Google Chrome's datetime-local inputs.

Parses a Year/Month/Date,Hour/Minute/Second-encoded Datetime from Text that was encoded with either no separators or any non-numeric character for each separator and with either of the following time formats:

  • %H:%M
  • %H:%M:%S

That is, the seconds and subseconds part is optional. If it is not provided, it is assumed to be zero. This format shows up in Google Chrome's datetime-local inputs.

Parses text that is formatted as either of the following:

  • %H:%M
  • %H:%M:%S

That is, the seconds and subseconds part is optional. If it is not provided, it is assumed to be zero. This format shows up in Google Chrome's datetime-local inputs.

Parse a Day/Month/Year,Hour/Minute/Second-encoded Datetime from Text that was encoded with either no separators or any non-numeric character for each separator and with either of the following time formats:

  • %H:%M
  • %H:%M:%S

That is, the seconds and subseconds part is optional. If it is not provided, it is assumed to be zero. This format shows up in Google Chrome's datetime-local inputs.

Parse a Month/Day/Year,Hour/Minute/Second-encoded Datetime from Text that was encoded with either no separators or any non-numeric character for each separator and with either of the following time formats:

  • %H:%M
  • %H:%M:%S

That is, the seconds and subseconds part is optional. If it is not provided, it is assumed to be zero.

Parses a Datetime from Text that was encoded with any of the following formats and with either no separators or any non-numeric character for each separator.

  • %Y-%M-%D %H:%M
  • %Y-%M-%D %H:%M:%S
  • %D-%M-%Y %H:%M
  • %D-%M-%Y %H:%M:%S
  • %M-%D-%Y %H:%M
  • %M-%D-%Y %H:%M:%S

That is, the seconds and subseconds part is optional. If it is not provided, it is assumed to be zero. Note that this is the least performant parser due to backtracking

Decodes Day/Month/Year,Hour/Minute/Second-encoded Datetime from Text that is encoded with either no separators or any non-numeric characters as separators, such as:

2017-01-05T23:13:05 2017-01-05 23:13:05 20170105 23:13:05 2018x01y01/23;50&29

Parse a Month/Day/Year,Hour/Minute/Second-encoded Datetime from Text with either no separators or any non-numeric character for each separator and with either of the following time formats:

  • %H:%M
  • %H:%M:%S

That is, the seconds and subseconds part is optional. If it is not provided, it is assumed to be zero.

Decode a Year/Month/Date,Hour/Minute/Second-encoded Datetime from Text that was encoded with the given DatetimeFormat and with either of the following time formats:

  • %H:%M
  • %H:%M:%S

That is, the seconds and subseconds part is optional. If it is not provided, it is assumed to be zero. This format shows up in Google Chrome's datetime-local inputs.

Decode a Year/Month/Date,Hour/Minute/Second-encoded Datetime from Text that was encoded with either no separators or any non-numeric character for each separator and with either of the following time formats:

  • %H:%M
  • %H:%M:%S

That is, the seconds and subseconds part is optional. If it is not provided, it is assumed to be zero. This format shows up in Google Chrome's datetime-local inputs.

Decode a Day/Month/Year,Hour/Minute/Second-encoded Datetime from Text that was encoded with with the given DatetimeFormat and with either of the following time formats:

  • %H:%M
  • %H:%M:%S

That is, the seconds and subseconds part is optional. If it is not provided, it is assumed to be zero. This format shows up in Google Chrome's datetime-local inputs.

Decode a Day/Month/Year,Hour/Minute/Second-encoded Datetime from Text that was encoded with either no separators or any non-numeric character for each separator and with either of the following time formats:

  • %H:%M
  • %H:%M:%S

That is, the seconds and subseconds part is optional. If it is not provided, it is assumed to be zero. This format shows up in Google Chrome's datetime-local inputs.

UTF-8 ByteString

Parses text that is formatted as either of the following:

  • %H:%M
  • %H:%M:%S

That is, the seconds and subseconds part is optional. If it is not provided, it is assumed to be zero. This format shows up in Google Chrome's datetime-local inputs.

UTF-8 Bytes

Encode a datetime with ISO-8601. The result does not include any indication of a time zone. If the subsecond part is zero, it is suppressed. Examples of output:

2021-01-05T23:00:51
2021-01-05T23:00:52.123
2021-01-05T23:00:53.674094347

Short Text

Offset Datetime

Text

UTF-8 ByteString

UTF-8 Bytes

Consume an ISO-8601-encoded datetime with offset. This will consume any of the following:

2021-12-05T23:01:09Z
2021-12-05T23:01:09.000Z
2021-12-05T23:01:09.123456789Z
2021-12-05T23:01:09+05:00
2021-12-05T23:01:09.357-11:00

ShortText

Offset

Text

UTF-8 ByteString

Timespan

Text

UTF-8 ByteString

TimeInterval

Types

newtypenewtype Day

A day represented as the modified Julian date, the number of days since midnight on November 17, 1858.

Constructors

Instances12Enum, Eq, Ord, Read, Show, Storable, …
  • Enum DayDefined in chronos-1.1.7.0 · Chronos
  • Eq DayDefined in chronos-1.1.7.0 · Chronos
  • Ord DayDefined in chronos-1.1.7.0 · Chronos
  • Read DayDefined in chronos-1.1.7.0 · Chronos
  • Show DayDefined in chronos-1.1.7.0 · Chronos
  • Storable DayDefined in chronos-1.1.7.0 · Chronos
  • NFData DayDefined in chronos-1.1.7.0 · Chronos
  • Hashable DayDefined in chronos-1.1.7.0 · Chronos
  • Prim DayDefined in chronos-1.1.7.0 · Chronos
  • FromJSON DayDefined in chronos-1.1.7.0 · Chronos
  • ToJSON DayDefined in chronos-1.1.7.0 · Chronos
  • Torsor Day IntDefined in chronos-1.1.7.0 · Chronos
newtypenewtype DayOfMonth

The day of the month.

Instances12Enum, Eq, Ord, Read, Show, NFData, …
newtypenewtype Month

The month of the year.

Constructors

Instances13Bounded, Enum, Eq, Ord, Read, Show, …
newtypenewtype Year

The number of years elapsed since the beginning of the Common Era.

Constructors

Instances5Eq, Ord, Read, Show, NFData
  • Eq YearDefined in chronos-1.1.7.0 · Chronos
  • Ord YearDefined in chronos-1.1.7.0 · Chronos
  • Read YearDefined in chronos-1.1.7.0 · Chronos
  • Show YearDefined in chronos-1.1.7.0 · Chronos
  • NFData YearDefined in chronos-1.1.7.0 · Chronos
newtypenewtype Offset

A UTC offset in minutes.

Constructors

Instances11Enum, Eq, Ord, Read, Show, NFData, …
newtypenewtype Time

POSIX time with nanosecond resolution.

Constructors

Instances12Bounded, Eq, Ord, Read, Show, Storable, …
newtypenewtype Timespan

A timespan. This is represented internally as a number of nanoseconds.

Constructors

Instances12Eq, Ord, Read, Show, Semigroup, Monoid, …

The precision used when encoding seconds to a human-readable format.

Constructors

Instances5Eq, Ord, Read, Show, NFData
datadata Date

A date as represented by the Gregorian calendar.

Instances7Enum, Eq, Ord, Read, Show, NFData, …
  • Enum DateDefined in chronos-1.1.7.0 · Chronos
  • Eq DateDefined in chronos-1.1.7.0 · Chronos
  • Ord DateDefined in chronos-1.1.7.0 · Chronos
  • Read DateDefined in chronos-1.1.7.0 · Chronos
  • Show DateDefined in chronos-1.1.7.0 · Chronos
  • NFData DateDefined in chronos-1.1.7.0 · Chronos
  • Torsor Date IntDefined in chronos-1.1.7.0 · Chronos
datadata OrdinalDate

An OrdinalDate is a Year and the number of days elapsed since the Year began.

Instances7Enum, Eq, Ord, Read, Show, NFData, …
datadata MonthDate

A month and the day of the month. This does not actually represent a specific date, since this recurs every year.

Instances5Eq, Ord, Read, Show, NFData
datadata Datetime

A Date as represented by the Gregorian calendar and a TimeOfDay. While the ToJSON instance encodes with a hyphen separator, the FromJSON instance allows any non-digit character to act as separator, using the lenient parser.

Instances7Eq, Ord, Read, Show, NFData, FromJSON, …
datadata DatetimeFormat

The format of a Datetime. In particular this provides separators for parts of the Datetime and nothing else.

Constructors

Instances5Eq, Ord, Read, Show, NFData
datadata OffsetFormat

Formatting settings for a timezone offset.

Constructors

Instances9Bounded, Enum, Eq, Ord, Read, Show, …
datadata DatetimeLocale a

Locale-specific formatting for weekdays and months. The type variable will likely be instantiated to Text or ByteString.

Constructors

Instances1NFData
datadata MeridiemLocale a

Locale-specific formatting for AM and PM.

Instances5Eq, Ord, Read, Show, NFData
datadata TimeInterval

A TimeInterval represents a start and end time. It can sometimes be more ergonomic than the Torsor API when you only care about whether or not a Time is within a certain range.

To construct a TimeInterval, it is best to use timeIntervalBuilder, which maintains the invariant that lowerBound interval <= upperBound interval (all functions that act on TimeIntervals assume this invariant).

Constructors

Instances6Bounded, Eq, Ord, Read, Show, NFData
datadata TimeParts

Holds all of the parts encoded by a Time. Can be used for formatting if what is presently in the API does not suffice.

Constructors

Instances4Eq, Read, Show, NFData

Lenses