Module Temporal.Duration

type t = duration

A duration (see duration).

val of_fields : months:int -> days:int -> seconds:int64 -> nanoseconds:int -> t

A duration from its components.

val to_fields : t -> int * int * int64 * int

The (months, days, seconds, nanoseconds) of a duration.

val neg : t -> t

The negated duration.

val add : t -> t -> t

Element-wise addition, normalising sub-second nanoseconds.

val sub : t -> t -> t

Element-wise subtraction, normalising sub-second nanoseconds.

val compare : t -> t -> int

Compare two durations.

val equal : t -> t -> bool

Whether two durations are equal.

val to_total_seconds : t -> int64

Total seconds, approximating months as 30 days.

val to_iso8601 : t -> string

Format as an ISO 8601 duration ("PnYnMnDTnHnMnS").

val of_iso8601 : string -> t option

Parse an ISO 8601 duration; None if invalid.

val to_span : t -> Ptime.Span.t option

Convert to a Ptime.Span.t; None if the duration has months (spans cannot represent them).

val of_span : Ptime.Span.t -> t

A duration from a Ptime.Span.t (months = 0).

val to_string : t -> string

Alias for to_iso8601.