Legend:
Library
Module
Module type
Parameter
Class
Class type
Civil dates in the proleptic Gregorian calendar.
Overview
This module implements a record type inhabited by proleptic Gregorian calendar dates. It also provides related functions and types to facilitate conversion to and from various formats for data interchange.
Days, weeks, and months are numbered according to ISO 8601. Days of the month are represented by integers from 1 to 31. Months of the year are represented by integers from 1 to 12. Days of the week are represented by integers from 1 to 7, where 1 is Monday and 7 is Sunday. Days of the year are numbered from 1 to 366, where only leap years contain day number 366. Weeks of the year are numbered from 1 to 53.
Additional, an ancillary private type is also provided here to facilitate conversions between a useful subset of dates and their corresponding Chronological Julian Day (CJD) numbers. These functions are useful for adjustments of dates by intervals measured in integral numbers of days. The first Chronological Julian Day, numbered zero, was 24 Nov 4714 BCE.
Types
type date = private
| Dateof{
year : int64;
(*
Astonomical year number.
*)
month : int;
(*
Months from January = 1 to December = 12
*)
day : int;
(*
Days 1 to 31.
*)
}
The private type inhabited by dates in a useful subset of the proleptic Gregorian calendar.
type cjd =
| CJDof int
The type inhabited by Chronological Julian Day numbers, which correspond to a useful subset of dates in the Gregorian calendar, including those dates that are accepted by the Internet time stamp format (RFC 3339).
Functions
val create : year:int64 ->month:int ->day:int ->date
Use create ~year ~month ~day to create a date according to the values of ~year, ~month and ~day. Raises Invalid_argument if the month or day values are not valid for year in the proleptic Gregorian calendar.
val is_valid : year:int64 ->month:int ->day:int -> bool
Using is_valid ~year ~month ~day returns true if year, month and day arguments specify a valid proleptic Gregorian date.
Use day_of_week d to compute the day of the week on which d occurs. Days of the week are numbered according to ISO 8601, i.e. from 1 to 7, starting on Monday and ending on Sunday.
to_cjd d computes the Chronological Julian Day number for d.
Gregorian dates between 12 Aug 2937947 BCE and 27 Feb 2935093 CE inclusive are convertible to Chronological Julian Day numbers on platforms where the Ocaml integer is a 31-bit integer. Accordingly, Failure is raised if the Chronological Julian Day corresponding to the date is outside the range that can be represented with an integer.