time
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 {
REALTIME = 0,
MONOTONIC = 1,
PROCESS_CPU = 2, BOOT = 7,
REALTIME_ALARM = 8, BOOT_ALARM = 9, TAI = 11, };
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
type clock = enum {
REALTIME = 0,
MONOTONIC = 1,
PROCESS_CPU = 2, BOOT = 7,
REALTIME_ALARM = 8, BOOT_ALARM = 9, TAI = 11, };
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
type duration = i64;
The elapsed time between two instants, in nanoseconds. The largest representable duration is about 290 years.
type instant
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
type interval = (instant, instant);
Represents a unique interval of time between two instants.
Constants
def HOUR
def HOUR: duration = 60 * MINUTE;
duration representing an hour.
def INSTANT_MAX
def INSTANT_MAX = instant {
sec = types::I64_MAX,
nsec = SECOND - 1,
};
The latest representable instant.
def INSTANT_MIN
def INSTANT_MIN = instant {
sec = types::I64_MIN,
nsec = 0,
};
The earliest representable instant.
def MICROSECOND
def MICROSECOND: duration = 1000 * NANOSECOND;
duration representing a single microsecond.
def MILLISECOND
def MILLISECOND: duration = 1000 * MICROSECOND;
duration representing a single millisecond.
def MINUTE
def MINUTE: duration = 60 * SECOND;
duration representing a minute.
def NANOSECOND
def NANOSECOND: duration = 1;
duration representing a single nanosecond.
def SECOND
def SECOND: duration = 1000 * MILLISECOND;
duration representing a second.
Functions
fn add
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
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 duration_to_timespec
fn duration_to_timespec(d: duration) rt::timespec;
Converts a duration to an rt::timespec. This function is non-portable.
fn duration_to_timeval
fn duration_to_timeval(d: duration) rt::timeval;
Converts a duration to an rt::timeval. This function is non-portable.
fn from_unix
fn from_unix(u: i64) instant;
Converts a given Unix timestamp to an instant.
fn instant_to_timespec
fn instant_to_timespec(t: instant) rt::timespec;
Converts an instant to an rt::timespec. This function is non-portable.
fn mult
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
fn now(clock: clock) instant;
Returns the current time for a given clock.
fn set
fn set(clock: clock, t: instant) (void | errors::noaccess);
Sets system clock to given time.
fn sleep
fn sleep(d: duration) void;
Yields the process to the kernel and returns after the requested duration.
fn timespec_to_instant
fn timespec_to_instant(ts: rt::timespec) instant;
Converts a rt::timespec to an instant. This function is non-portable.
fn unix
fn unix(i: instant) i64;
Converts a given instant to a Unix timestamp. Note, nanosecond information is lost during conversion.