package orsetto

  1. Overview
  2. Docs
Legend:
Library
Module
Module type
Parameter
Class
Class type

Computations with the Temps Atomique International (TAI) timescale.

Overview

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:

  • acquire the current time in TAI64N format.
  • compare, add and subtract values.
  • convert between TAI64N values and a portable external format called the "TAI64N label", which is essentially an array of twelve octets.
  • convert between TAI64N values and the float values returned by the 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 detail

Types
type t

Abstract values of TAI64N type

Functions

Equivalence and total order relations

include Cf_relations.Std with type t := t
val compare : t -> t -> int

Use compare a b to compare a and b, returning 0 if the two values have equal ordering, 1 if a precedes b and -1 if a succeeds b.

val equal : t -> t -> bool

Use equal a b to compare a and b, returning true if the two values are equivalent, otherwise false.

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 not less 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 12 octets 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 Oni_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.

OCaml

Innovation. Community. Security.