Rata Die is a system for assigning numbers to calendar days, using a base date of 1 January 0001.
This module exposes the same functions as the Date module, but it uses raw
Int values as date representations.
This may be useful if you need dates as comparables. Otherwise, the Date
module offers an opaque type for better type-safety.
Create a date from a year, month, and day of the month; out-of-range day values will be clamped.
fromCalendarDate 2018 Sep 26Create a date from a year and day of the year; out-of-range day values will be clamped.
fromOrdinalDate 2018 314Create a date from a week-numbering year, week number, and weekday; out-of-range week values will be clamped.
fromWeekDate 2018 26 WedGet the current local date.
Convert a date to a string using a pattern as a template.
fromCalendarDate 2007 Mar 15
|> toFormattedString "EEEE, MMMM d, y"
-- "Thursday, March 15, 2007"Each alphabetic character in the pattern represents date or time information; the number of times a character is repeated specifies the form of the name to use (e.g. "Tue", "Tuesday") or the padding of numbers (e.g. "1", "01"). Formatting characters are escaped within single-quotes; a single-quote is escaped as a sequence of two single-quotes, whether appearing inside or outside an escaped sequence.
Patterns are based on Date Format Patterns in Unicode Technical Standard #35. Only the following subset of formatting characters are available:
"y" -- year
"Y" -- week-numbering year
"Q" -- quarter
"M" -- month
"w" -- week number
"d" -- day
"D" -- ordinal day
"E" -- day of week
"e" -- weekday number / day of weekThe non-standard pattern field "ddd" is available to indicate the day of the month with an ordinal suffix (e.g. "1st", "15th"), as the current standard does not include such a field.
fromCalendarDate 2007 Mar 15
|> toFormattedString "MMMM ddd, y"
-- "March 15th, 2007"Attempt to create a date from a string in ISO 8601 format. Calendar dates, week dates, and ordinal dates are all supported in extended and basic format.
fromIsoString "2018-09-26"
fromIsoString "2018-W26-3"
fromIsoString "2018-314"The string must represent a valid date; unlike fromCalendarDate and
friends, any out-of-range values will fail to produce a date.
fromIsoString "2018-02-29"
-- Err "Invalid calendar date"Convenience function for formatting a date in ISO 8601 extended format.
fromCalendarDate 2007 Mar 15
|> toIsoString
-- "2007-03-15"Move a date by some number of units.
fromCalendarDate 2018 Sep 26
|> add Weeks -2
-- fromCalendarDate 2018 Sep 12When adding Years or Months, day values are clamped to the end of the
month if necessary.
fromCalendarDate 2000 Jan 31
|> add Months 1
-- fromCalendarDate 2000 Feb 29Find the difference, as a number of some units, between two dates.
diff Months
(fromCalendarDate 2007 Mar 15)
(fromCalendarDate 2007 Sep 1)
-- 5Round up a date to the beginning of the closest interval. The resulting date will be greater than or equal to the one provided.
fromCalendarDate 2018 May 11
|> ceiling Tuesday
-- fromCalendarDate 2018 May 15Round down a date to the beginning of the closest interval. The resulting date will be less than or equal to the one provided.
fromCalendarDate 2018 May 11
|> floor Tuesday
-- fromCalendarDate 2018 May 8Create a list of dates, at rounded intervals, increasing by a step value, between two dates. The list will start on or after the first date, and end before the second date.
range Day 2
(fromCalendarDate 2018 May 8)
(fromCalendarDate 2018 May 14)
-- [ fromCalendarDate 2018 May 8
-- , fromCalendarDate 2018 May 10
-- , fromCalendarDate 2018 May 12
-- ]Extracts the day of the year.
Extracts the day of the month.
Extracts the week-numbering year; this is not always the same as the calendar year.
Numbers 1–7 represent Monday–Sunday.
Convenience functions for converting dates to records.