module Date:Date operations.sig..end
This module implements operations on dates. A date is a triple (year, month, day).
All the dates should belong to
[January, 1st 4713 BC; January 22th, 3268 AC] (called the Julian period).
An Out_of_bounds exception is raised if you attempt to create a date
outside the Julian period.
If a date d does not exists and if d_bef (resp. d_aft) is
the last (resp. first) existing date before (resp. after) d,
d is automatically coerced to d_aft + d - d_bef - 1.
For example, both dates "February 29th, 2003" and
"February 30th, 2003" do not exist and they are coerced respectively to the
date "Mars 1st, 2003" and "Mars 2nd, 2003".
This rule is called the coercion rule.
As an exception to the coercion rule, the date belonging to
[October 5th, 1582; October 14th, 1582] do not exist and an Undefined
exception is raised if you attempt to create such a date.
Those dropped days correspond to the change from the Julian to the Gregorian
calendar.
type t
type day =
| |
Sun |
| |
Mon |
| |
Tue |
| |
Wed |
| |
Thu |
| |
Fri |
| |
Sat |
type month =
| |
Jan |
| |
Feb |
| |
Mar |
| |
Apr |
| |
May |
| |
Jun |
| |
Jul |
| |
Aug |
| |
Sep |
| |
Oct |
| |
Nov |
| |
Dec |
typeyear =int
int.typefield =[ `Day | `Month | `Week | `Year ]
exception Out_of_bounds
exception Undefined
[October 5th, 1582; October 14th, 1582].val make : year -> int -> int -> tmake year month day makes the date year-month-day.
A BC year y corresponds to the year -(y+1).
E.g. the years (5 BC) and (1 BC) respectively correspond to the years
(-4) and 0.val lmake : year:year -> ?month:int -> ?day:int -> unit -> tmake.
The default value of month and day is 1.val today : unit -> tTime_Zone.current ()).val from_jd : int -> tfrom_jd 0 returns the date 4713 BC-1-1.val from_mjd : int -> tfrom_mjd 0 returns the date 1858-11-17.val days_in_month : t -> intdays_in_month (make 2003 6 26) returns 30.val day_of_week : t -> dayday_of_week (make 2003 6 26) returns Thu.val day_of_month : t -> intday_of_month (make 2003 6 26) returns 26.val day_of_year : t -> intday_of_year (make 2003 1 5) returns 5
and day_of_year (make 2003 12 28) returns 362.val week : t -> intweek (make 2000 1 3) returns 1 and week (make 2000 1 2) returns
52. week (make 2003 12 28) returns 52 and week (make 2003 12 29)
returns 1.val month : t -> monthmonth (make 2003 6 26) returns Jun.val year : t -> yearyear (make 2003 6 26) returns 2003.val to_jd : t -> intto_jd (make (-4712) 1 1) returns 0.val to_mjd : t -> intto_mjd (make 1858 11 17) returns 0.val compare : t -> t -> intPervasives.compare.val equal : t -> t -> bool(=).val is_leap_day : t -> booltrue if a date is a leap day
(i.e. February, 24th of a leap year); false otherwise.val is_gregorian : t -> booltrue if a date belongs to the Gregorian calendar;
false otherwise.val is_julian : t -> booltrue iff a date belongs to the Julian calendar;
false otherwise.val to_unixtm : t -> Unix.tmUnix.tm type.
The field is_isdst is always false. The fields Unix.tm_sec,
Unix.tm_min and Unix.tm_hour are irrelevant.val from_unixtm : Unix.tm -> tto_unixtm. Assume the current time zone.val to_unixfloat : t -> floatto_unixfloat (make 1970 1 1)
returns 0.0. So such a float is convertible with those of the Unix
module. The fractional part of the result is always 0.val from_unixfloat : float -> tto_unixfloat. Ignore the fractional part of the argument.
Assume the current time zone.val to_business : t -> year * int * dayto_business (make 2000 1 3) returns 2000, 1, Mon and to_business
(make 2000 1 2) returns 1999, 52, Sun. to_business (make 2003 12 28)
returns 2003, 52, Sun and to_business (make 2003 12 29) returns 2004,
1, Mon.val from_business : year -> int -> day -> tto_business respecting ISO-8601.
Raise Invalid_argument if the week is bad.
Notice that business weeks at the beginning and end of the year
can sometimes have year numbers which don't match the real year.val int_of_day : day -> intval day_of_int : int -> dayint_of_day.
Raise Invalid_argument if the argument $\notin 1; 7$.val int_of_month : month -> intval month_of_int : int -> monthint_of_month.
Raise Invalid_argument if the argument $\notin 1; 12$.module Period:sig..end
val add : t -> Period.t -> tadd d p returns d + p.
E.g. add (make 2003 12 31) (Period.month 1) returns the date
2004-1-31 and add (make 2003 12 31) (Period.month 2) returns the date
2004-3-2 (following the coercion rule describes in the introduction).val sub : t -> t -> Period.tsub d1 d2 returns the period between d1 and d2.val rem : t -> Period.t -> trem d p is equivalent to add d (Period.opp p).val next : t -> field -> tnext d f returns the date corresponding to the next specified field.\\
E.g next (make 2003 12 31) `Month returns the date 2004-1-31
(i.e. one month later).val prev : t -> field -> tprev d f returns the date corresponding to the previous specified
field.
E.g prev (make 2003 12 31) `Year returns the date 2002-12-31
(i.e. one year ago).val is_leap_year : year -> booltrue if a year is a leap year; false otherwise.val same_calendar : year -> year -> booltrue if two years have the same calendar; false otherwise.val days_in_year : ?month:month -> year -> int
days_in_year ~month y returns the number of days in the year y up to
the end of the given month. Thus days_in_year ~month:Dec y is the same as
days_in_year y.
val weeks_in_year : year -> intval week_first_last : int -> year -> t * tval nth_weekday_of_month : year -> month -> day -> int -> tnth_weekday_of_month y m d n returns the n-th day d in the month
m of the year y (for instance the 3rd Thursday of the month).val century : year -> intcentury 2000 returns 20 and century 2001 returns 21.val millenium : year -> intmillenium 2000 returns 2 and millenium 2001 returns 3.val solar_number : year -> int
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 -> intThe 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 -> int
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 -> int
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 -> t
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.
val carnaval : year -> tcarnaval y is easter y - 48.val mardi_gras : year -> tmardi_gras y is easter y - 47.val ash : year -> tash y is easter y - 46.val palm : year -> tpalm y is easter y - 7.val easter_friday : year -> teaster_friday y is easter y - 2.val easter_saturday : year -> teaster_saturday y is easter y - 1.val easter_monday : year -> teaster_monday y is easter y + 1.val ascension : year -> tascension y is easter y + 39.val withsunday : year -> twithsunday y is easter y + 49.val withmonday : year -> twithmonday y is easter y + 50.val corpus_christi : year -> tcorpus_christi y is easter + 60.