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 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 second.

Functions are provided that:

  • acquire the current time in TAI64 format.
  • compare, add and subtract values.
  • convert between TAI64 values and a portable external format called the "TAI64 label", which is essentially an array of eight octets.
  • convert between TAI64 values and the float values returned by the Unix.time function.

Constants are also provided that define the boundaries of valid TAI64 representations.

Warning: This implementation obtains the current time of day using the POSIX time() 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.

Warning! The internal logic used here for adjusting the difference between the UTC time scale and TAI timescale due to leap seconds uses data that originates at the International Earth Rotation and Reference System Service, which determines whether and when to insert or delete leap seconds into the UTC timescale. These announcements are made every six months in an IERS bulletin, and provided as a public service by the United States National Institute of Standards and Technology (NIST) and the Internet Engineering Task Force (IETF) at the following locations:

<https://www.ietf.org/timezones/data/leap-seconds.list> <ftp://ftp.nist.gov/pub/time/leap-seconds.list>

The data in the current implementation expires on December 28, 2021.

Types
type t

Abstract values of TAI64 type

Exceptions
type exn += private
  1. | Range_error

Result not representable in TAI64 format.

type exn += private
  1. | Label_error

Input is not a valid TAI64 label

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 TAI64, obtained by reading the current time from the POSIX time() function, and adjusting for leap seconds.

val first : t

The earliest TAI epoch representable in the TAI64 format, corresponding to 16:14:36 on July 14, 146138509945 BCE (in the continuous TAI timescale, which diverges from UTC by not introducing leap seconds). The label is 0000000000000000.

val last : t

The latest TAI epoch representable in the TAI64 format, corresponding to 7:43:49 on June 19, 146138514283 CE (in the TAI timescale, which diverges from UTC by not introducing leap seconds). The label is 7fffffffffffffff.

val to_unix_time : t -> float

Converts a TAI64 value to a value consistent with the result of calling the Unix.gettimeofday function. The output is not adjusted for leap seconds into UTC from TAI.

val of_unix_time : float -> t

Converts a value consistent with the result of calling the Unix.time function into a TAI64 value. The input is assumed to be adjusted for leap seconds into TAI from UTC.

val to_label : t -> string

Returns a string of 8 octets containing the TAI64 label corresponding to the TAI64 value of its argument.

val of_label : string -> t

Interprets the argument as a TAI64 label and returns the corresponding TAI64 value. Raises Label_error if the label is invalid.

val add : t -> int -> t

Add seconds to a TAI64 value. Raises Range_error if the result is not a valid TAI64 value.

val add_int32 : t -> int32 -> t

Add seconds to a TAI64 value. Raises Range_error if the result is not a valid TAI64 value.

val add_int64 : t -> int64 -> t

Add seconds to a TAI64 value. Raises Range_error if the result is not a valid TAI64 value.

val sub : t -> t -> int64

Subtract one TAI64 value from another. sub t0 t1 returns the number of seconds before t0 that t1 denotes.

OCaml

Innovation. Community. Security.