Lunar.Zoned_datetimeA Datetime.t associated with a Timezone.t.
Internally stored as a UTC datetime with an associated timezone offset.
The concept behind a zone-based datetime can be explained as follows: A datetime (expressed in local time) is associated with a time zone, and the APIs as a whole allow the internal resolution to be hidden.
The API is generally similar to that of Datetime, except that certain functions that handle durations are omitted (to allow users to choose whether or not to convert to local time on demand).
type error = | Invalid_string of string| Invalid_datetime of Datetime.error| Invalid_timezone of Timezone.errorType listing errors that may occur when working with zoned datetime.
exception Invalid_zoned_datetime of errorAn exception used for unsafe function.
val from_local_datetime : ?tz:Timezone.t -> Datetime.t -> tfrom_local_datetime ?tz dt attach a timezone to a regular Datetime.t. The default Timezone tz is Timezone.utc.
val make :
?tz:Timezone.t ->
?at:(int * int * int) ->
year:int ->
month:Month.t ->
day:int ->
unit ->
(t, Datetime.error) resultmake ?tz ?at ~year ~month ~day () create and validate a zoned datetime. The default Timezone tz is Timezone.utc.
See Datetime.make
val make' :
?tz:Timezone.t ->
?at:(int * int * int) ->
year:int ->
month:int ->
day:int ->
unit ->
(t, Datetime.error) resultmake' ?at ~year ~month ~day () create and validate a zoned datetime. see make. Take an integer rather than a Month.t. The default Timezone tz is Timezone.utc.
See Datetime.make'
val make_exn :
?tz:Timezone.t ->
?at:(int * int * int) ->
year:int ->
month:Month.t ->
day:int ->
unit ->
tmake_exn ?at ~year ~month ~day () create and validate a datetime like make but raise Invalid_datetime if the validation doesn't succeed. The default Timezone tz is Timezone.utc.
val make_exn' :
?tz:Timezone.t ->
?at:(int * int * int) ->
year:int ->
month:int ->
day:int ->
unit ->
tmake_exn' ?at ~year ~month ~day () create and validate a zoned datetime, like make' but raise Invalid_datetime if the validation doesn't succeed. The default Timezone tz is Timezone.utc.
from_string s try to read a date from a string (using the format year-mon-dayThh:mm:ssTZ, according to RFC3339).
val from_string_exn : string -> tfrom_string_exn s try to read a date from a string (using the format year-mon-dayThh:mm:ssTZ, according to RFC3339) and raise and exception if it fails.
val from : ?tz:Timezone.t -> Date.t -> Time.t -> tfrom d t creates a zoned datetime object for the given date, d and a given time t. The default Timezone tz is Timezone.utc.
See Datetime.from
val from_date : ?tz:Timezone.t -> Date.t -> tfrom_date d creates a zoned datetime object for the given date, d, at midnight. The default Timezone tz is Timezone.utc.
val from_duration : ?tz:Timezone.t -> Duration.t -> tfrom_duration d converts a duration to a date. 0 is the 1970-01-01 at 00:00:00. The default Timezone tz is Timezone.utc.
val from_utc : Datetime.t -> tfrom_utc dt creates a zoned datetime from an UTC datetime (does not any conversion).
val epoch : ?tz:Timezone.t -> unit -> tReturns the 1st January 1970 at midnight. The default Timezone tz is Timezone.utc.
See Datetime.epoch
val timezone : t -> Timezone.ttimezone zdt returns the attached timezone to the given zdt.
val on_utc : (Datetime.t -> 'a) -> t -> 'aon_utc f zdt apply f on the datetime (in UTC) of zdt.
val on_local : (Datetime.t -> 'a) -> t -> 'aon_local f zdt apply f on the local datetime of zdt.
val map_utc : (Datetime.t -> Datetime.t) -> t -> tmap_utc f zdt applies f to the underlying UTC datetime.
This transforms the absolute instant while preserving the timezone.
val map_local : (Datetime.t -> Datetime.t) -> t -> tmap_local f zdt applies f to the underlying local datetime.
This transforms the relative instant while preserving the timezone.
val to_utc : t -> Datetime.tto_utc zdt returns a date in UTC format (subtracting the time zone offset)
to_zoned_utc zdt returns a zoned datetime expressed in UTC.
This keeps the same instant but changes the timezone to UTC. Equivalent to change_timezone with Timezone.utc.
val to_local_datetime : t -> Datetime.tto_local_datetime zdt returns the date with the time zone offset applied.
val to_datetime : tz:Timezone.t -> t -> Datetime.tto_datetime ~tz zdt displays the datetime using the specified time zone tz.
val change_timezone : tz:Timezone.t -> t -> tchange_timezone ~tz zdt changes the timezone of the given zdt by tz.
val add : Duration.t -> t -> tadd duration zdt compute a new date adding duration to the given zdt.
val sub : Duration.t -> t -> tsub duration zdt compute a new date substracting duration to the given zdt.
add_seconds number_of_seconds zoned_datetime add number_of_seconds to the given zoned_datetime.
sub_seconds number_of_seconds zoned_datetime remove number_of_seconds to the given zoned_datetime.
add_minutes number_of_minutes zoned_datetime add number_of_minutes to the given zoned_datetime.
sub_minutes number_of_minutes zoned_datetime remove number_of_minutes to the given zoned_datetime.
add_hours number_of_hours zoned_datetime add number_of_hours to the given zoned_datetime.
sub_hours number_of_hours zoned_datetime remove number_of_hours to the given datime.
add_days number_of_days zoned_datetime add number_of_days to the given zoned_datetime.
sub_days number_of_days zoned_datetime remove number_of_days to the given zoned_datetime.
add_weeks number_of_weeks zoned_datetime add number_of_weeks to the given zoned_datetime (a week is 7 days).
sub_weeks number_of_weeks zoned_datetime remove number_of_weeks to the given zoned_datetime (a week is 7 days).
add_months number_of_months zoned_datetime add number_of_months to the given zoned_datetime.
add_months number_of_months zoned_datetime remove number_of_months to the given zoned_datetime.
add_quarters number_of_quarters zoned_datetime add number_of_quarters to the given zoned_datetime.
add_quarters number_of_quarters zoned_datetime remove number_of_quarters to the given zoned_datetime.
add_years number_of_years zoned_datetime add number_of_years to the given zoned_datetime.
sub_years number_of_years zoned_datetime remove number_of_years to the given zoned_datetime.
val diff : t -> t -> Duration.tdiff d1 d2 returns the difference (in Duration.t) between d1 and d2.
The main difference between the add/sub and succ/pred operations lies in how the result is truncated. add and sub are standard arithmetic operations: you add or subtract a duration. succ and pred, on the other hand, calculate the next zoned datetime step. See Time.succ and Date.succ.
pred_second zdt returns the zoned datetime at the previous second. See pred.
succ_day ?where:pred from returns the first following zoned datetime that satisfies the predicate pred starting from the date from (exclusive). Note: If the predicate always returns false, the function never terminates.
pred_day ~where:pred from returns the first previous zoned datetime that satisfies the predicate pred starting from the date from (exclusive). Note: If the predicate always returns false, the function never terminates.
succ_day_of_week weekday from returns the first following zoned datetime corresponding to the specified day of the week.
pred_day_of_week weekday from returns the first previous zoned datetime corresponding to the specified day of the week.
succ_week zdt returns the first day of the next week.
pred_week zdt returns the first day of the previous week.
Most of the operations involve the local representation of the zoned date.
with_local_time t zdt sets the local time component.
This changes the underlying instant so that the resulting local datetime has the given time.
with_local_date date zoned_datetime replace the date of the given zoned_datetime.
This changes the underlying instant so that the resulting local datetime has the given time.
start_of_minute zdt returns the zoned datetime at the start of the current minute.
end_of_minute zdt returns the zoned datetime at the end of the current minute.
start_of_hour zdt returns the zoned datetime at the start of the current hour.
start_of_day zdt Returns a zoned datetime set to the start of the day (midnight).
end_of_day zdt Returns a zoned datetime set to the end of the day (23:59:59).
at_noon is start_of_afternoon.
start_of_week ?week_start zdt Returns the first day of the week (defined by week_start; default: Monday).
end_of_week ?week_start zdt Returns the last day of the week (defined by week_start - 1; default: Monday).
start_of_month zdt returns the first day of the month of the given zoned datetime zdt.
end_of_month zdt returns the last day of the month of the given zoned datetime zdt.
start_of_quarter zdt returns the first day of the quarter of the given zoned datetime zdt.
end_of_quarter zdt returns the last day of the quarter of the given zoned datetime zdt.
start_of_year zdt returns the first day of the year of the given zoned datetime d.
end_of_year zdt returns the last day of the year of the given zoned datetime zdt.
age ~birthday current returns the age calculated from birthday using the given zoned datetime current as the current date.
A negative duration can produce very strange results, which is why durations are converted to absolute values in rounding functions.
val truncate : [< Resolution.t ] -> t -> ttruncate resolution d truncates d to the beginning of the period specified by resolution. See Datetime.truncate and Time.truncate.
All units smaller than resolution are discarded.
val floor : [< Resolution.t ] -> t -> tfloor resolution d is truncate resolution d.
val round : [< Resolution.t ] -> t -> tround resolution d rounds d to the nearest boundary of the period specified by resolution. See Datetime.round and Timetime.round.
val ceil : [< Resolution.t ] -> t -> tceil resolution d rounds d up to the next boundary of the period specified by resolution. If d is already aligned with resolution, it is returned unchanged. See Datetime.ceil and Time.ceil.
Every predicate are computed on the local-time representation.
val is_am : t -> boolis_am dt returns true if the time of the given dt is between 00:00:00 and 11:59:59, false otherwise.
val is_pm : t -> boolis_pm dt returns true if the time of the given dt is between 12:00:00 and 23:59:59, false otherwise.
val is_noon : t -> boolis_noon dt returns true if the time of the given dt is exactly 12:00:00, false otherwise.
val is_midnight : t -> boolis_midnight dt returns true if the time of the given dt is exactly 00:00:00, false otherwise.
val is_morning : t -> boolis_morning dt returns true if the time of the given dt is between 05:00:00 and 11:59:59, false otherwise.
val is_afternoon : t -> boolis_afternoon dt returns true if the time of the given dt is between 12:00:00 and 16:59:59, false otherwise.
val is_evening : t -> boolis_evening dt returns true if the time of the given dt is between 17:00:00 and 20:59:59, false otherwise.
val is_night : t -> boolis_night dt returns true if the time of the given dt is between 21:00:00 and 04:59:59, false otherwise.
val is_weekend : t -> boolis_weekend dt returns true if the date of the given dt is on Saturday or Sunday.
val is_weekday : t -> boolis_weekday dt returns true if the date of the given dt is not on Saturday or Sunday.
is_day_of_week wd d returns true if the current day of week is the given one wd, false otherwise.
is_first_day_of_week ?week_start d returns true if the given date d is the first day of the week.
is_last_day_of_week ?week_start d returns true if the given date d is the last day of the week.
val is_leap_year : t -> boolis_leap_year dt returns true if year d is a leap year, false otherwise.
val is_first_day_of_month : t -> boolis_first_day_of_month dt returns true if the date of the given dt is the first day of the month.
val is_last_day_of_month : t -> boolis_last_day_of_month dt returns true if the date of the given dt is the last day of the month.
val is_first_day_of_quarter : t -> boolis_first_day_of_quarter d returns true if the date of the given dt is the first day of the current quarter.
val is_last_day_of_quarter : t -> boolis_last_day_of_q d returns true if the date of the given dt is the last day of the current quarter.
val is_first_day_of_year : t -> boolis_first_day_of_year dt returns true if the date of the given dt is the first day of the year.
val is_last_day_of_year : t -> boolis_last_day_of_year dt returns true if the date of the given dt is the last day of the year.
clamp ~min ~max x restricts the x to the inclusive interval [min, max].
is_earlier ~than x returns true if x is (strictly) earlier than than, false otherwise.
is_later ~than x returns true if x is (strictly) later than than, false otherwise.
val to_string : t -> stringto_string zdt returns a string representation of the given zdt (using the RFC ISO 8601).
Please note that the comparison function used by Maps and Sets differs from the compare function described above. This is because the compare function uses the UTC representation, so two dates in different time zones may be considered equal. Here, however, the time zone is included in the comparison.
module Range : sig ... endmodule Infix : sig ... endCommon and useful infix operators.
include module type of Infixval (+) : t -> Duration.t -> td + dur is add
val (-) : t -> Duration.t -> td - dur is sub