module Cf_tai64n:sig
..end
Computations with the Temps Atomique International (TAI) timescale.
This module (and its cognate Cf_tai64
) defines an abstract type and
associated functions for computations with values representing epochs in
the Temps Atomique International (TAI) timescale. Values are represented
internally with the TAI64 format defined by Dan Bernstein, and support
precision to the nearest nanosecond.
Functions are provided that:
Unix.gettimeofday
function.Constants are also provided that define the boundaries of valid TAI64N representations.
Warning: This implementation obtains the current time of day using the
POSIX gettimeofday()
function, which returns a value based on the UTC
timescale (but with leap seconds "elided" in a way that makes conversions
between POSIX time, Standard Time and TAI a perilous undertaking). See the
Cf_stdtime
module for details.
type
t
Abstract values of TAI64N type
val compare : t -> t -> int
A total ordering function, defined so that the Cf_tai64n
module has the
signature of the Cf_ordered.Total_T
module type. compare a b
compares
two TAI64N values and returns either -1
, 0
, or 1
depending on the
relative total ordering of the values.
val now : unit -> t
Returns the current time in TAI64N, obtained by reading the current time
from the POSIX gettimeofday()
function, and adjusting for leap
seconds. (Currently, the leap seconds table is hardcoded into the library,
and the most recent leap second announcement was for Dec 31, 1998.)
val first : t
The earliest TAI epoch representable in the TAI64N format. The TAI64N
label is 00000000 00000000 00000000
.
val last : t
The latest TAI epoch representable in the TAI64N format. The TAI64N label
is 7fffffff ffffffff 3b9ac9ff
.
val compose : Cf_tai64.t -> int -> t
Use compose s ns
to compose a TAI64N value from a TAI64 value s
and an
offset of ns
nanoseconds. Raises Invalid_argument
if the number of
nanoseconds is greater than 1012.
val decompose : t -> Cf_tai64.t * int
Use decompose x
to separate the TAI64N value x
into a TAI64 value and
an offset in nanoseconds.
val to_unix_time : t -> float
Converts a TAI64 value to a value consistent with the result of calling the
Unix.gettimeofday
function.
val of_unix_time : float -> t
Converts a value consistent with the result of calling the
Unix.gettimeofday
function into a TAI64N value.
val to_label : t -> string
Returns a string of 8 characters containing the TAI64N label corresponding to the TAI64N value of its argument.
val of_label : string -> t
Interprets the argument as a TAI64N label and returns the corresponding
TAI64N value. Raises Cf_tai64.Label_error
if the label is not a valid
TAI64N label.
val add : t -> float -> t
Add seconds to a TAI64N value. Raises Cf_tai64.Range_error
if the result
is not a valid TAI64N value.
val sub : t -> t -> float
Subtract one TAI64N value from another. sub t0 t1
returns the number of
seconds before t0
that t1
denotes.