Module Date

type t

An abstract date, opaque outside this module.

type format =
  1. | Long
    (*

    "22nd of June, 2001"

    *)
  2. | Short
    (*

    "22/06/2001"

    *)
  3. | Super_short
    (*

    "22/06"

    *)
type error =
  1. | Invalid_date of {
    1. day : int;
    2. month : int;
    3. year : int;
    }
val of_dmy : (int * int * int) -> (t, error) Stdlib.result

of_dmy (day, month, year) builds a date, or Error if the tuple doesn't correspond to a real calendar date (e.g. day 30 in February, month 13).

val of_dmy_exn : (int * int * int) -> t

Like of_dmy, but raises Invalid_argument instead of returning Error. Intended for literal dates written directly in source (e.g. content declarations) where an invalid date is a bug you want to catch immediately, not a value to handle at runtime.

val compare : t -> t -> int

Orders dates chronologically.

val to_string : ?format:format -> t -> string

Renders a date as a string. Defaults to Short if ~format is omitted.