Module Date.Period

A period is the number of days between two dates.

Arithmetic operations

type +'a p constraint 'a = [< field ]
include Period.S with type +'a period = 'a p
type +'a period = 'a p

Type of a period.

Period is an additive monoid

val empty : 'a period

The empty period.

val add : 'a period -> 'a period -> 'a period

Addition of periods.

val sub : 'a period -> 'a period -> 'a period

Substraction of periods.

val opp : 'a period -> 'a period

Opposite of a period.

Periods are comparable

val equal : 'a period -> 'b period -> bool

Equality function between two periods.

  • since 1.09.0
val compare : 'a period -> 'b period -> int

Comparison function between two periods.

val hash : 'a period -> int

Hash function for periods.

  • since 2.0

Constructors

val make : int -> int -> int -> t

make year month day makes a period of the specified length.

val lmake : ?year:int -> ?month:int -> ?day:int -> unit -> t

Labelled version of make. The default value of each argument is 0.

val year : int -> [> `Year ] period

year n makes a period of n years.

val month : int -> [> `Year | `Month ] period

month n makes a period of n months.

val week : int -> [> `Week | `Day ] period

week n makes a period of n weeks.

val day : int -> [> `Week | `Day ] period

day n makes a period of n days.

Getters

exception Not_computable
  • since 1.04
val nb_days : 'a period -> int

Number of days in a period.

  • raises Not_computable

    if the number of days is not computable. @example nb_days (day 6) returns 6 @example nb_days (year 1) raises Not_computable because a year is not a constant number of days.

  • since 1.04
  • deprecated

    since 2.02: use safe_nb_days instead

val safe_nb_days : [< `Week | `Day ] period -> int

Equivalent to nb_days but never raises any exception.

  • since 2.02
val ymd : 'a period -> int * int * int

Number of years, months and days in a period. @example ymd (make 1 2 3) returns 1, 2, 3.

  • since 1.09.0