package timmy-jsoo

  1. Overview
  2. Docs
Legend:
Library
Module
Module type
Parameter
Class
Class type
include module type of Timmy.Date

A day of a month of a year.

A day of a month of a year.

Type

type t = Timmy.Date.t = {
  1. day : int;
    (*

    The day of the month.

    *)
  2. month : Month.t;
    (*

    The month of the year.

    *)
  3. year : int;
    (*

    The year.

    *)
}

A date.

Construction

val make : year:Base.int -> month:Month.t -> day:Base.int -> (Timmy.Date.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 -> Timmy.Date.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

val add_days : Timmy.Date.t -> Base.int -> Timmy.Date.t

add_days date n is the date occuring n days after date.

val max_month_day : Base.int -> Base.int -> Base.int

max_month_day year month is the last day of the given month of year. It can be 31, 30, 29 or 28.

val weekday : Timmy.Date.t -> Weekday.t

weekday date is the day of the week on date.

Time conversions

val of_time : timezone:Timmy.Timezone.t -> Timmy.Time.t -> Timmy.Date.t

of_time ~timezone date is the date on date in timezone.

val to_time : timezone:Timmy.Timezone.t -> Timmy.Date.t -> Timmy.Time.t

to_time ~timezone date is the time at midnight on date in timezone.

Comparison

include Base.Comparable.S with type t := t
val equal : Timmy.Date.t -> Timmy.Date.t -> bool
val compare : Timmy.Date.t -> Timmy.Date.t -> int
val ascending : Timmy.Date.t -> Timmy.Date.t -> int
val descending : Timmy.Date.t -> Timmy.Date.t -> int
val between : Timmy.Date.t -> low:Timmy.Date.t -> high:Timmy.Date.t -> bool
val clamp_exn : Timmy.Date.t -> min:Timmy.Date.t -> max:Timmy.Date.t -> Timmy.Date.t
val clamp : Timmy.Date.t -> min:Timmy.Date.t -> max:Timmy.Date.t -> Timmy.Date.t Base__.Or_error.t
type comparator_witness = Timmy.Date.comparator_witness
val comparator : (Timmy.Date.t, comparator_witness) Base__Comparator.comparator

Operators

module O = Timmy.Date.O

Convenience module to only pull operators.

include module type of O

Convenience module to only pull operators.

Convenience module to only pull operators.

Convenience module to only pull operators.

include Base.Comparable.Infix with type t := Timmy__.Date.t
val (>=) : Timmy.Date.t -> Timmy.Date.t -> bool
val (<=) : Timmy.Date.t -> Timmy.Date.t -> bool
val (=) : Timmy.Date.t -> Timmy.Date.t -> bool
val (>) : Timmy.Date.t -> Timmy.Date.t -> bool
val (<) : Timmy.Date.t -> Timmy.Date.t -> bool
val (<>) : Timmy.Date.t -> Timmy.Date.t -> bool
val (+) : Timmy.Date.t -> Base.int -> Timmy.Date.t

date + n is add_days date n.

end - start is the duration elapsed from start to end.

Scalar conversions

Pretty-print

pp f date prints date to f in RFC3339 format, eg. 2021-10-04.

val pp_human : Timmy.Date.t Fmt.t

pp_human f date prints date to f in an unspecified human readable english format, eg. "August 1st 2022".

val pp_relative : ?default:Timmy.Date.t Fmt.t -> reference:Timmy.Date.t -> Timmy.Date.t Fmt.t

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 : Timmy.Date.t -> Base.string

to_string date is the RCF3339 representation of date, eg. 2021-10-04.

val of_string : Base.string -> (Timmy.Date.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

val to_tuple : Timmy.Date.t -> Base.int * Base.int * Base.int

to_tuple { year; month; day} is (year, Month.to_int month, day).

val of_tuple : (Base.int * Base.int * Base.int) -> (Timmy.Date.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) -> Timmy.Date.t

of_tuple (year, month, day) is the corresponding date.

  • raises Failure

    if the date is invalid.

S-expression

val to_sexp : Timmy.Date.t -> Base.Sexp.t

to_sexp date is a s-expression representing date.

Integer

val to_int : Timmy.Date.t -> Base.int

to_int date is the Julian day of date.

val of_int : Base.int -> Timmy.Date.t

of_int jd is the date of the Julian day jd.

OCaml

Innovation. Community. Security.