githubEdit

Time Library (Time)

Library for Time ("system" feature).

Functions for working with time. Requires the "system" feature flag to be enabled. Includes timestamps (Time.now()) as well as common time formats (like RFC-3339) that are used in APIs and across systems.

Example Usage

#[main]
fn main() {
    const now = Time.now(); // default units are ms
    sleep(50ms);
    pln(Time.diff(now) as seconds); // having units is really nice
}

Time.diff(prev: float) -> ms

Convenience function for getting the difference in milliseconds between a previous timestamp (takes any units, default ms) and the current time. Shorthand for (Time.now() - prev).

const ts = Time.now();
sleep(50ms);
const diff = Time.diff(ts);
assert(diff >= 50ms);

Time.diff_ns(prev: float) -> ns

Convenience function for getting the difference in nanoseconds between a previous timestamp (takes any units, default ns) and the current time. Shorthand for (Time.now_ns() - prev).

Time.from_rfc2822(time: str) -> ms

Returns a unix timestamp (milliseconds since Epoch) representing the given RFC-2822 string.

Time.from_rfc3339(time: str) -> ms

Returns a Unix timestamp (milliseconds since the Epoch) representing the given RFC-3339 string.

Time.now() -> ms

Return the current time in milliseconds since the Unix Epoch (Unix timestamp).

Time.now_ns() -> ns

Return the current time in nanoseconds since the Unix Epoch (Unix timestamp).

Time.now_rfc2822() -> str

Returns a string representing the current time according to the RFC-2822 specification.

Time.now_rfc3339() -> str

Returns a string representing the current time according to the RFC-3339 specification.

Time.sleep(time: float = 1000ms) -> void

Alias for Std.sleep, instructing this process to sleep for a given amount of time (default units are milliseconds).

Time.to_rfc2822(time: float) -> str

Returns a string representing the given timestamp according to the RFC-2822 specification.

Time.to_rfc3339(time: float) -> str

Returns a string representing the given timestamp according to the RFC-3339 specefication.

Last updated