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

Modulechronos-1.1.6.1Haskell2010

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.

  • 25 types
  • 212 values
  • Packagechronos-1.1.6.1
  • Exports237
  • LanguageHaskell2010
  • LicenceBSD-3-Clause
  • SourceChronos.hs

Functions

0 declarations

Current

valuenow :: IO Time
#

Get the current time from the system clock.

valuetoday :: IO Day
#

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

valueepoch :: Time
#

The Unix epoch, that is 1970-01-01 00:00:00.

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.

valuew3c :: DatetimeFormat
#

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))
valueslash :: DatetimeFormat
#

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))
valuehyphen :: DatetimeFormat
#

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

valuedaysInMonth
  1. :: Bool

    Is this a leap year?

  2. -> Month

    Month of year

  3. -> Int
#

Return the number of days in a given month.

valueisLeapYear :: Year -> Bool
#

Is the Year a leap year?

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

Textual Conversion

0 declarations

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

valueencodeIso8601 :: 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.

Parses text that was encoded in DMY, YMD, or MDY format with optional seconds and any non-numeric character as separators.

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.

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.123000000
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

25 declarations
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.6.1 · Chronos
  • Eq DayDefined in chronos-1.1.6.1 · Chronos
  • Ord DayDefined in chronos-1.1.6.1 · Chronos
  • Read DayDefined in chronos-1.1.6.1 · Chronos
  • Show DayDefined in chronos-1.1.6.1 · Chronos
  • Storable DayDefined in chronos-1.1.6.1 · Chronos
  • NFData DayDefined in chronos-1.1.6.1 · Chronos
  • Hashable DayDefined in chronos-1.1.6.1 · Chronos
  • Prim DayDefined in chronos-1.1.6.1 · Chronos
  • FromJSON DayDefined in chronos-1.1.6.1 · Chronos
  • ToJSON DayDefined in chronos-1.1.6.1 · Chronos
  • Torsor Day IntDefined in chronos-1.1.6.1 · 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.6.1 · Chronos
  • Ord YearDefined in chronos-1.1.6.1 · Chronos
  • Read YearDefined in chronos-1.1.6.1 · Chronos
  • Show YearDefined in chronos-1.1.6.1 · Chronos
  • NFData YearDefined in chronos-1.1.6.1 · 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, …
datadata SubsecondPrecision
#

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.6.1 · Chronos
  • Eq DateDefined in chronos-1.1.6.1 · Chronos
  • Ord DateDefined in chronos-1.1.6.1 · Chronos
  • Read DateDefined in chronos-1.1.6.1 · Chronos
  • Show DateDefined in chronos-1.1.6.1 · Chronos
  • NFData DateDefined in chronos-1.1.6.1 · Chronos
  • Torsor Date IntDefined in chronos-1.1.6.1 · 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 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

26 declarations