Module CalendarLib.Date
include Date_sig.S
Datatypes
type field= Period.date_fieldThe different fields of a date.
- since
- 2.02
type -'a dateconstraint 'a = [< field ]Type of a date, without specifying any precision level.
- since
- 2.02
Exceptions
Constructors
val make : year -> int -> int -> tval lmake : year:year -> ?month:int -> ?day:int -> unit -> tLabelled version of
make. The default value ofmonthanddayis1.- raises Out_of_bounds
when a date is outside the Julian period.
- raises Undefined
when a date belongs to
[October 5th, 1582; October 14th, 1582].
- since
- 1.05
val make_year : int -> [< `Year ] datemake_year ymakes a date only represented by its yeary. The month and the day of such a date are not relevant.- since
- 2.02
val make_year_month : int -> int -> [< `Year | `Month ] datemake_year_month y mmakes a date only represented by its yearyand its monthm. The day of such a date is not relevant.- since
- 2.02
val today : unit -> tDate of the current day (based on
Time_Zone.current ()).
Getters
Dates are comparable
val equal : 'a date -> 'b date -> boolEquality function between two dates.
- see Utils.Comparable.html#VALequal
Utils.Comparable.equal
- since
- 1.09.0
val compare : 'a date -> 'b date -> intComparison function between two dates.
- see Utils.Comparable.html#VALcompare
Utils.Comparable.compare
val hash : 'a date -> intHash function for dates.
- see Utils.Comparable.html#VALhash
Utils.Comparable.hash
- since
- 2.0
Boolean operations on dates
val is_valid_date : year -> int -> int -> boolval is_leap_day : t -> boolReturn
trueif a date is a leap day (i.e. February, 24th of a leap year);falseotherwise.
val is_gregorian : t -> boolReturn
trueif a date belongs to the Gregorian calendar;falseotherwise.
val is_julian : t -> boolReturn
trueiff a date belongs to the Julian calendar;falseotherwise.
Coercions
val to_unixtm : t -> Unix.tmConvert a date into the
Unix.tmtype. The fieldis_isdstis alwaysfalse. The fieldsUnix.tm_sec,Unix.tm_minandUnix.tm_hourare irrelevant.- since
- 1.01
val from_unixtm : Unix.tm -> tInverse of
to_unixtm. Assume the current time zone.- since
- 1.01
val to_unixfloat : t -> floatConvert a date to a float such than
to_unixfloat (make 1970 1 1)returns0.0. So such a float is convertible with those of theUnixmodule. The fractional part of the result is always0.- since
- 1.01
val from_unixfloat : float -> tInverse of
to_unixfloat. Ignore the fractional part of the argument. Assume the current time zone.- since
- 1.01
val to_business : t -> year * int * dayval from_business : year -> int -> day -> tInverse of
to_businessrespecting ISO-8601. Notice that business weeks at the beginning and end of the year can sometimes have year numbers which don't match the real year.- raises Invalid_argument
if the date is bad.
- since
- 1.09.0
val int_of_day : day -> intConvert a day to an integer respecting ISO-8601. So, Monday is 1, Tuesday is 2, ..., and sunday is 7.
val day_of_int : int -> dayInverse of
int_of_day.- raises Invalid_argument
if the argument does not belong to
1; 7.
val int_of_month : month -> intConvert a month to an integer respecting ISO-8601. So, January is 1, February is 2 and so on.
val month_of_int : int -> monthInverse of
int_of_month.- raises Invalid_argument
if the argument does not belong to
1; 12.
Period
module Period : sig ... endA period is the number of days between two dates.
Arithmetic operations on dates and periods
val add : 'a date -> 'a Period.period -> 'a dateval sub : 'a date -> 'a date -> [> `Week | `Day ] Period.periodsub d1 d2returns the period betweend1andd2.
val precise_sub : 'a date -> 'a date -> Period.tprecise_sub d1 d2returns the period betweend1andd2. It is equivalent tosub, but:- the period is expressed with a number of years, months and days, not only with a number of days;
- it is less efficient.
- since
- 2.03
val rem : 'a date -> 'a Period.period -> 'a daterem d pis equivalent toadd d (Period.opp p).- raises Out_of_bounds
when the resulting date is outside the Julian period.
- raises Undefined
when the resulting date belongs to
[October 5th, 1582; October 14th, 1582].
Operations on years
val is_leap_year : year -> boolReturn
trueif a year is a leap year;falseotherwise.
val same_calendar : year -> year -> boolReturn
trueif two years have the same calendar;falseotherwise.
val days_in_year : ?month:month -> year -> intNumber of days in a year.
days_in_year ~month yreturns the number of days in the yearyup to the end of the given month. Thusdays_in_year ~month:Dec yis the same asdays_in_year y.
val weeks_in_year : year -> intNumber of weeks in a year.
val week_first_last : int -> year -> t * tReturn the first and last days of a week in a year.
- since
- 1.08
val nth_weekday_of_month : year -> month -> day -> int -> tnth_weekday_of_month y m d nreturns then-th daydin the monthmof the yeary(for instance the 3rd Thursday of the month).- since
- 1.09.0
val century : year -> intval millenium : year -> intval solar_number : year -> intSolar number.
In the Julian calendar there is a one-to-one relationship between the Solar number and the day on which a particular date falls.
val indiction : year -> intIndiction.
The Indiction was used in the middle ages to specify the position of a year in a 15 year taxation cycle. It was introduced by emperor Constantine the Great on 1 September 312 and ceased to be used in 1806.
The Indiction has no astronomical significance.
val golden_number : year -> intGolden number.
Considering that the relationship between the moon's phases and the days of the year repeats itself every 19 years, it is natural to associate a number between 1 and 19 with each year. This number is the so-called Golden number.
val epact : year -> intEpact.
The Epact is a measure of the age of the moon (i.e. the number of days that have passed since an "official" new moon) on a particular date.
val easter : year -> tEaster Sunday.
In the Christian world, Easter (and the days immediately preceding it) is the celebration of the death and resurrection of Jesus in (approximately) AD 30.
Carnaval Monday.
carnaval yiseaster y - 48.- since
- 1.09.0