time+x86_64 +linux

The time module provides basic timekeeping primitives and system clock access. See time::chrono:: for timescales, timezones, and other chronology primitives. See time::date:: for the Gregorian chronology.

Submodules

Index

Types

type clock = enum {
	// The current wall-clock time. This may jump forwards or backwards in
	// time to account for leap seconds, NTP adjustments, etc.
	REALTIME = 0,
	// The current monotonic time. This clock measures from some undefined
	// epoch and is not affected by leap seconds, NTP adjustments, and
	// changes to the system time: it always increases by one second per
	// second.
	MONOTONIC = 1,
	PROCESS_CPU = 2, // Measures CPU time consumed by the calling process.
	// Time since the system was booted. Increases monotonically and, unlike
	// [[MONOTONIC]], continues to tick while the system is suspended.
	BOOT = 7,
	REALTIME_ALARM = 8, // This clock is like [[REALTIME]], but will wake the system if it is suspended.
	BOOT_ALARM = 9, // This clock is like [[BOOT]], but will wake the system if it is suspended.
	TAI = 11, // A system-wide clock derived from wall-clock time but ignoring leap seconds.
};
type duration = i64;
type instant = struct {
	sec: i64,
	nsec: i64,
};
type interval = (instant, instant);

Constants

def HOUR: duration = 60 * MINUTE;
def INSTANT_MAX = instant {
	sec = types::I64_MAX,
	nsec = SECOND - 1,
};
def INSTANT_MIN = instant {
	sec = types::I64_MIN,
	nsec = 0,
};
def MICROSECOND: duration = 1000 * NANOSECOND;
def MILLISECOND: duration = 1000 * MICROSECOND;
def MINUTE: duration = 60 * SECOND;
def NANOSECOND: duration = 1;
def SECOND: duration = 1000 * MILLISECOND;

Functions

fn add(i: instant, x: duration) instant;
fn compare(a: instant, b: instant) i8;
fn diff(a: instant, b: instant) duration;
fn duration_to_timespec(d: duration) rt::timespec;
fn duration_to_timeval(d: duration) rt::timeval;
fn from_unix(u: i64) instant;
fn instant_to_timespec(t: instant) rt::timespec;
fn mult(i: instant, f: f64) instant;
fn now(clock: clock) instant;
fn set(clock: clock, t: instant) (void | errors::noaccess);
fn sleep(d: duration) void;
fn timespec_to_instant(ts: rt::timespec) instant;
fn unix(i: instant) i64;

Types

type clock[link]

type clock = enum {
	// The current wall-clock time. This may jump forwards or backwards in
	// time to account for leap seconds, NTP adjustments, etc.
	REALTIME = 0,
	// The current monotonic time. This clock measures from some undefined
	// epoch and is not affected by leap seconds, NTP adjustments, and
	// changes to the system time: it always increases by one second per
	// second.
	MONOTONIC = 1,
	PROCESS_CPU = 2, // Measures CPU time consumed by the calling process.
	// Time since the system was booted. Increases monotonically and, unlike
	// [[MONOTONIC]], continues to tick while the system is suspended.
	BOOT = 7,
	REALTIME_ALARM = 8, // This clock is like [[REALTIME]], but will wake the system if it is suspended.
	BOOT_ALARM = 9, // This clock is like [[BOOT]], but will wake the system if it is suspended.
	TAI = 11, // A system-wide clock derived from wall-clock time but ignoring leap seconds.
};

An enumeration of clocks available on this system. Different clocks represent times from different epochs, and have different characteristics with regards to leap seconds, NTP adjustments, and so on. All systems provide the REALTIME and MONOTONIC clocks at least; use of other clocks is not guaranteed to be portable.

type duration[link]

type duration = i64;

The elapsed time between two instants, in nanoseconds. The largest representable duration is about 290 years.

type instant[link]

type instant = struct {
	sec: i64,
	nsec: i64,
};

Represents a specific instant in time as seconds (+nanoseconds) since an arbitrary epoch. Instants may only be meaningfully compared with other instants sourced from the same clock, or handled by the same time::chrono::timescale

type interval[link]

type interval = (instant, instant);

Represents a unique interval of time between two instants.

Constants

def HOUR[link]

def HOUR: duration = 60 * MINUTE;

duration representing an hour.

def INSTANT_MAX[link]

def INSTANT_MAX = instant {
	sec = types::I64_MAX,
	nsec = SECOND - 1,
};

The latest representable instant.

def INSTANT_MIN[link]

def INSTANT_MIN = instant {
	sec = types::I64_MIN,
	nsec = 0,
};

The earliest representable instant.

def MICROSECOND[link]

def MICROSECOND: duration = 1000 * NANOSECOND;

duration representing a single microsecond.

def MILLISECOND[link]

def MILLISECOND: duration = 1000 * MICROSECOND;

duration representing a single millisecond.

def MINUTE[link]

def MINUTE: duration = 60 * SECOND;

duration representing a minute.

def NANOSECOND[link]

def NANOSECOND: duration = 1;

duration representing a single nanosecond.

def SECOND[link]

def SECOND: duration = 1000 * MILLISECOND;

duration representing a second.

Functions

fn add[link]

fn add(i: instant, x: duration) instant;

Adds a duration to an instant, returning an instant further in the future (given a positive duration), or further in the past (given a negative duration).

fn compare[link]

fn compare(a: instant, b: instant) i8;

Returns -1 if a precedes b, 0 if a and b are simultaneous, or +1 if b precedes a.

fn diff[link]

fn diff(a: instant, b: instant) duration;

Returns the duration from instant "a" to instant "b".

fn duration_to_timespec[link]

fn duration_to_timespec(d: duration) rt::timespec;

Converts a duration to an rt::timespec. This function is non-portable.

fn duration_to_timeval[link]

fn duration_to_timeval(d: duration) rt::timeval;

Converts a duration to an rt::timeval. This function is non-portable.

fn from_unix[link]

fn from_unix(u: i64) instant;

Converts a given Unix timestamp to an instant.

fn instant_to_timespec[link]

fn instant_to_timespec(t: instant) rt::timespec;

Converts an instant to an rt::timespec. This function is non-portable.

fn mult[link]

fn mult(i: instant, f: f64) instant;

Scales the given instant's scalar value by a factor 'f'. Make sure to know what epoch you're dealing with.

fn now[link]

fn now(clock: clock) instant;

Returns the current time for a given clock.

fn set[link]

fn set(clock: clock, t: instant) (void | errors::noaccess);

Sets system clock to given time.

fn sleep[link]

fn sleep(d: duration) void;

Yields the process to the kernel and returns after the requested duration.

fn timespec_to_instant[link]

fn timespec_to_instant(ts: rt::timespec) instant;

Converts a rt::timespec to an instant. This function is non-portable.

fn unix[link]

fn unix(i: instant) i64;

Converts a given instant to a Unix timestamp. Note, nanosecond information is lost during conversion.