Time v0.1.0

Source
C's <time.h>: calendar time, processor time and the conversions between them.

time_t

pub type time_t = int64

C's time_t: a calendar time as an arithmetic value. What the value counts is implementation-defined by the standard, and is seconds since the Unix epoch on every supported target. Rux/Time's Timestamp is the one that says so as a contract.

See also: https://en.cppreference.com/c/chrono/time_t

Source

clock_t

// Windows
pub type clock_t = int32

// Linux · FreeBSD
pub type clock_t = int64

// macOS
pub type clock_t = uint64

C's clock_t: processor time as an arithmetic value. long on every supported target, and long is not one width: the Universal CRT makes it 32 bits while every supported Unix makes it 64, and Darwin spells the same type unsigned. Declaring it as a fixed 64-bit integer, as this once did, reads four bytes of whatever followed the result on Windows. Spelled as the primitive rather than as c_long, because a type alias cannot name one declared in another file of this package. The width is the same thing said twice. FreeBSD's definition is the one value here not confirmed against a running system; the eight-target fixture gate is what checks it.

See also: https://en.cppreference.com/c/chrono/clock_t

Source

clock

pub extern func clock() -> clock_t

Returns the approximate processor time used by the program.

See also: https://en.cppreference.com/c/chrono/clock

Source

Returns: the processor time used, or -1 when it is not available

difftime

pub extern func difftime(
    time_end: time_t,
    time_beg: time_t
) -> float64

Computes the difference in seconds between two calendar times.

See also: https://en.cppreference.com/c/chrono/difftime

Source

Parameters

NameTypeDescription
time_endtime_tthe later clock reading
time_begtime_tthe earlier clock reading

Returns: the seconds between the two readings

gmtime

pub extern func gmtime(timer: *time_t) -> *tm

Converts a time_t object to calendar time expressed as UTC.

See also: https://en.cppreference.com/c/chrono/gmtime

Source

Parameters

NameTypeDescription
timer*time_tthe time value, or null

Returns: a pointer to storage the C runtime owns and the next call may reuse, or null

localtime

pub extern func localtime(timer: *time_t) -> *tm

Converts a time_t object to calendar time expressed as local time.

See also: https://en.cppreference.com/c/chrono/localtime

Source

Parameters

NameTypeDescription
timer*time_tthe time value, or null

Returns: a pointer to storage the C runtime owns and the next call may reuse, or null

mktime

pub extern func mktime(time_ptr: *tm) -> time_t

Converts calendar time to a time_t object, normalizing the tm structure.

See also: https://en.cppreference.com/c/chrono/mktime

Source

Parameters

NameTypeDescription
time_ptr*tmthe time value to convert

Returns: the time value, or -1 when the components cannot be represented

time

pub extern func time(timer: *time_t) -> time_t

Returns the current calendar time since the epoch.

See also: https://en.cppreference.com/c/chrono/time

Source

Parameters

NameTypeDescription
timer*time_tthe time value, or null

Returns: the current time, or -1 when it is not available

TIME_UTC

pub const TIME_UTC: int32 = 1;

TIME_UTC: the time base naming seconds since the epoch, the only one C defines.

Source

CLOCKS_PER_SEC

// Windows
pub const CLOCKS_PER_SEC: int64 = 1000;

// Linux · macOS · FreeBSD
pub const CLOCKS_PER_SEC: int64 = 1000000;

CLOCKS_PER_SEC: how many clock ticks make one second on this target.

Source

TimespecGet

pub func TimespecGet(
    ts: &var timespec,
    base: c_int
) -> c_int

Fills ts with the current time on the given base. ts is borrowed and written, so callers pass the value directly. base is read by value and TIME_UTC is the only base C defines. Returns base on success and zero on failure, which is the one way this reports one. Runs in constant time and allocates nothing.

Source

Parameters

NameTypeDescription
ts&var timespecreceives the reading
basec_intwhich time base to read; TIME_UTC is the only one C defines

Returns: base on success, or zero on failure