Calendar_sig.S.Period

# Module Calendar_sig.S.Period

    module Period: sig .. end

A period is the number of seconds between two calendars.

### Arithmetic operations

    type +[< Period.date_field ] period

    type t = Period.date_field period

Type of a period.

### Period is an additive monoid

    val empty : [< Period.date_field ] period

The empty period.

    val add : ([< Period.date_field > `Day `Week ] as 'a) period ->
           'a period -> 'a period

Addition of periods.

    val sub : ([< Period.date_field > `Day `Week ] as 'a) period ->
           'a period -> 'a period

Substraction of periods.

    val opp : ([< Period.date_field > `Day `Week ] as 'a) period ->
           'a period

Opposite of a period.

### Periods are comparable

    val equal : [< Period.date_field ] period ->
           [< Period.date_field ] period -> bool

Equality function between two periods.
Since 1.09.0
See also Utils.Comparable.equal

    val compare : [< Period.date_field ] period ->
           [< Period.date_field ] period -> int

Comparison function between two periods.
See also Utils.Comparable.compare

    val hash : [< Period.date_field ] period -> int

Hash function for periods.
Since 2.0
See also Utils.Comparable.hash

### Constructors

    val make : int ->
           int -> int -> int -> int -> Calendar_sig.S.second -> t

`make year month day hour minute second` makes a period of the specified length.

    val lmake : ?year:int ->
           ?month:int ->
           ?day:int ->
           ?hour:int ->
           ?minute:int ->
           ?second:Calendar_sig.S.second -> unit -> t

Labelled version of `make`. The default value of each argument is `0`.
Those functions have the same behavious as those defined in `Date_sig.S.Period`.

    val year : int -> [< Period.date_field > `Year ] period

See also Date_sig.S.Period.year

    val month : int -> [< Period.date_field > `Month `Year ] period

See also Date_sig.S.Period.month

    val week : int -> [< Period.date_field > `Day `Week ] period

See also Date_sig.S.Period.week

    val day : int -> [< Period.date_field > `Day `Week ] period

See also Date_sig.S.Period.day
Those functions have the same behavious as those defined in .

    val hour : int -> [< Period.date_field > `Day `Week ] period

See also Time_sig.S.Period.hour

    val minute : int -> [< Period.date_field > `Day `Week ] period

See also Time_sig.S.Period.minute

    val second : Calendar_sig.S.second ->
           [< Period.date_field > `Day `Week ] period

See also Time_sig.S.Period.second

### Coercions

    val from_date : ([< Period.date_field ] as 'a) Date.Period.period ->
           'a period

Convert a date period to a calendar period.

    val from_time : ([< Period.date_field ] as 'a) Time.Period.period ->
           'a period

Convert a time period to a calendar period.

    val to_date : ([< Date.field ] as 'a) period -> 'a Date.Period.period

Convert a calendar period to a date period. The fractional time period is ignored.
Example: `to_date (hour 60)` is equivalent to `Date.Period.days 2`.

    exception Not_computable

`= Date.Period.Not_computable`.
Since 1.04

    val to_time : ([< Period.date_field ] as 'a) period ->
           'a Time.Period.period

Deprecated.since 2.02: use `Calendar_sig.S.Period.safe_to_time` instead
Convert a calendar period to a date period.
Since 1.04
Raises `Not_computable` if the time period is not computable.
Examples:

- `to_time (year 1)` raises `Not_computable` because a year is not a constant number of days.
- `to_time (second 30)` returns a time period of `30` seconds
- `to_time (day 6)` returns a time period of `24 * 3600 * 6 = 518400` seconds

    val safe_to_time : ([< `Day | `Week ] as 'a) period ->
           'a Time.Period.period

Equivalent to `Calendar_sig.S.Period.to_time` but never raises any exception.
Since 2.02

    val ymds : [< Period.date_field ] period ->
           int * int * int * Calendar_sig.S.second

Number of years, months, days and seconds in a period.
Since 1.09.0
Examples:

- `ymds (make (-1) (-2) (-3) (-1) (-2) (-3)` returns `-1, -2, -4, 82677`.
- `ymds (make 1 2 3 1 2 3)` returns `1, 2, 3, 3723`