package timmy
Install
Dune Dependency
Authors
Maintainers
Sources
md5=6d1d9c3e2ccd8376c009e5b93b24de7e
sha512=96c844a6041f4cf42d1efa02ba12a3a184780beb64bfd5d5693a2338f57ad22d4793ff34a23a9a81a47954dbf489bc644077840d0435013494499b2b3405330b
doc/timmy/Timmy/Date/index.html
Module Timmy.Date
A day of a month of a year.
A day of a month of a year.
Type
type t = {
day : int;
(*The day of the month.
*)month : Month.t;
(*The month of the year.
*)year : int;
(*The year.
*)
}
A date.
type js = Js_of_ocaml.Js.date Js_of_ocaml.Js.t
Construction
val make :
year:Base.int ->
month:Month.t ->
day:Base.int ->
(t, Base.string) Base.Result.t
make ~year ~month ~day
is { day; month; year }
if it represents a valid date or a relevant error message otherwise.
val make_overflow :
?day_truncate:Base.bool ->
year:Base.int ->
month:Base.int ->
day:Base.int ->
Base.unit ->
t
make_overflow
is make
except out of range components will readjust the next component until the date becomes valid. This enables to perform simple arithmetics over dates like adding or substracting days and months without worrying about month and year boundaries and readjust the final results.
Month below 1 will underflow to previous years and month above 12 will overflow to the next years, eg. make ~year:2021 ~month:-1 ~day:1 ()
is {year = 2020; month = 11; day = 1}
and make ~year:2021 ~month:25 ~day:1 ()
is {year = 2023; month = 1; day = 1}
.
Unless truncate_day
is true, days below 1 will underflow to the previous months and days past the last day of the month will overflow to the next months, eg. make_overflow ~year:1985 ~month:2 ~day:29 ()
is {year = 1985; month = 3; day = 1}
.
If truncate_day
is true, the day is clipped to the valid range for the current month. This is useful to do arithmetics on months without risking the day overflowing to the next months if the new month is shorter, eg. make_overflow ~day_truncate:true ~year:1985 ~month:(1 + 1) ~day:31 ()
is {year = 1985; month = 2; day = 28}
.
Time manipulations
max_month_day year month
is the last day of the given month
of year
. It can be 31, 30, 29 or 28.
Time conversions
val of_time : timezone:Timezone.t -> Time.t -> t
of_time ~timezone date
is the date on date
in timezone
.
val to_time : timezone:Timezone.t -> t -> Time.t
to_time ~timezone date
is the time at midnight on date
in timezone
.
Comparison
include Base.Comparable.S with type t := t
include Base.Comparisons.S with type t := t
include Base.Comparisons.Infix with type t := t
compare t1 t2
returns 0 if t1
is equal to t2
, a negative integer if t1
is less than t2
, and a positive integer if t1
is greater than t2
.
ascending
is identical to compare
. descending x y = ascending y x
. These are intended to be mnemonic when used like List.sort ~compare:ascending
and List.sort ~cmp:descending
, since they cause the list to be sorted in ascending or descending order, respectively.
clamp_exn t ~min ~max
returns t'
, the closest value to t
such that between t' ~low:min ~high:max
is true.
Raises if not (min <= max)
.
val clamp : t -> min:t -> max:t -> t Base.Or_error.t
include Base.Comparator.S with type t := t
val comparator : (t, comparator_witness) Base.Comparator.comparator
Operators
module O : sig ... end
Convenience module to only pull operators.
include module type of O
Scalar conversions
Pretty-print
pp_human f date
prints date
to f
in an unspecified human readable english format, eg. "August 1st 2022".
pp_relative ?default ~reference f date
prints date
to f
in an unspecified human readable english format relative to reference
, eg. "today", "last Sunday", "Tuesday".
If no relevant relative format is found, default
is used. It defaults to pp_human
.
String
val to_string : t -> Base.string
to_string date
is the RCF3339 representation of date
, eg. 2021-10-04.
val of_string : Base.string -> (t, Base.string) Base.Result.t
of_string s
is the date represented by s
as per RCF3339 or a relevant error message if it is invalid.
Tuple
to_tuple { year; month; day}
is (year, Month.to_int month, day)
.
val of_tuple :
(Base.int * Base.int * Base.int) ->
(t, Base.string) Base.Result.t
of_tuple (year, month, day)
is the corresponding date if it is valid or a relevant error message otherwise.
val of_tuple_exn :
?here:Base.Source_code_position.t ->
(Base.int * Base.int * Base.int) ->
t
of_tuple (year, month, day)
is the corresponding date.
S-expression
val to_sexp : t -> Base.Sexp.t
to_sexp date
is a s-expression representing date
.
Integer
to_int date
is the Julian day of date
.
of_int jd
is the date of the Julian day jd
.