Module Ptime.Span

POSIX time spans.

WARNING. A POSIX time span is not equal to an SI second based time span.

POSIX time spans

type t

The type for signed picosecond precision POSIX time spans. A value of this type represent the POSIX duration between two POSIX timestamps.

val v : (int * int64) -> t

v s is like of_d_ps s but raises Invalid_argument if s is not in the right range. Use of_d_ps to deal with untrusted input.

val zero : t

zero is the neutral element of add.

val of_d_ps : (int * int64) -> t option

of_d_ps (d, ps) is a span for the signed POSIX picosecond span d * 86_400e12 + ps. d is a signed number of POSIX days and ps a number of picoseconds in the range [0;86_399_999_999_999_999L]. None is returned if ps is not in the right range.

val to_d_ps : t -> int * int64

to_d_ps d is the span d as a pair (d, ps) expressing the POSIX picosecond span d * 86_400e12 + ps with ps in the range [0;86_399_999_999_999_999L]

val of_int_s : int -> t

of_int_s secs is a span from the signed integer POSIX second span secs.

val to_int_s : t -> int option

to_int_s d is the span d as a signed integer POSIX second span, if int's range can represent it (note that this depends on Sys.word_size). Subsecond precision numbers are truncated.

val of_float_s : float -> t option

of_float_s secs is a span from the signed floating point POSIX second span d. Subpicosecond precision numbers are truncated.

None is returned if secs cannot be represented as a span. This occurs on Stdlib.nan or if the duration in POSIX days cannot fit on an int (on 32-bit platforms this means the absolute magnitude of the duration is greater than ~2'941'758 years).

val to_float_s : t -> float

to_float_s s is the span s as floating point POSIX seconds.

Warning. The magnitude of s may not be represented exactly by the floating point value.

val of_mtime_span : Mtime.Span.t -> t

of_mtime_span span is a span from the monotonic span span.

val to_mtime_span : t -> Mtime.Span.t option

of_mtime_span span is the absolute value of span as a monotonic span or None if span cannot be represented.

Predicates

val equal : t -> t -> bool

equal d d' is true if and only if d and d' are the same time span.

val compare : t -> t -> int

compare d d' is a total order on durations that is compatible with signed time span order.

val is_shorter : t -> than:t -> bool

is_shorter span ~than is true if and only if span lasts stricly less than than.

val is_longer : t -> than:t -> bool

is_longer span ~than is true if and only if span lasts stricly more than than.

Arithmetic

Note. The following functions rollover on overflows.

val neg : t -> t

neg d is the span d negated.

val add : t -> t -> t

add d d' is d + d'.

val sub : t -> t -> t

sub d d' is d - d'.

val abs : t -> t

abs d is the absolute value of span d.

Pretty printing

val pp_d_ps : Stdlib.Format.formatter -> t -> unit

pp_d_ps ppf d prints an unspecified, approximative, representation of d on ppf.