logos.std.time

Module std · package logos-std

Types

structDuration

struct Duration

A span of time, stored as a signed nanosecond count (range ~±292 years). Negative values are valid (represent time going backwards).

Implements: Copy

Fields

nanos: i64

Methods

fn as_micros(self: Duration) -> i64

Returns the total whole microseconds, truncated toward zero.

fn as_millis(self: Duration) -> i64

Returns the total whole milliseconds, truncated toward zero.

fn as_nanos(self: Duration) -> i64

Returns the total nanoseconds in this duration.

fn as_secs(self: Duration) -> i64

Returns the total whole seconds, truncated toward zero.

fn is_negative(self: Duration) -> bool

Returns true if the duration is negative.

fn is_zero(self: Duration) -> bool

Returns true if the duration is exactly zero.

fn subsec_nanos(self: Duration) -> i64

Returns the sub-second nanosecond remainder; negative for negative durations.

structInstant

struct Instant

A measurement from a monotonic clock. The absolute value has no meaning — only differences between Instants.

Implements: Copy

Fields

nanos: i64

Methods

fn elapsed(self: Instant) -> Duration

Returns the elapsed time since this Instant was captured.

fn nanos_since_epoch(self: Instant) -> i64

Returns the raw nanosecond reading; meaningful only relative to other Instants.

fn since(self: Instant, earlier: Instant) -> Duration

Returns the elapsed time from earlier to self (self - earlier). Negative if earlier is actually later; never panics (unlike Rust).

structSystemTime

struct SystemTime

Wall-clock time (Unix epoch = 1970-01-01 00:00:00 UTC). May go backwards on NTP adjustments.

Fields

nanos: i64

Methods

fn since(self: SystemTime, earlier: SystemTime) -> Duration

Returns the duration from earlier to self (self - earlier); may be negative.

fn unix_millis(self: SystemTime) -> i64

Returns whole milliseconds since the Unix epoch, truncated toward zero.

fn unix_nanos(self: SystemTime) -> i64

Returns nanoseconds since the Unix epoch.

fn unix_secs(self: SystemTime) -> i64

Returns whole seconds since the Unix epoch, truncated toward zero.

Functions

fnduration_from_micros

fn duration_from_micros(us: i64) -> Duration

Creates a Duration from a microsecond count.

fnduration_from_millis

fn duration_from_millis(ms: i64) -> Duration

Creates a Duration from a millisecond count.

fnduration_from_nanos

fn duration_from_nanos(ns: i64) -> Duration

Creates a Duration from a nanosecond count.

fnduration_from_secs

fn duration_from_secs(s: i64) -> Duration

Creates a Duration from a whole-second count.

fninstant_now

fn instant_now() -> Instant

Returns the current Instant from the monotonic clock (CLOCK_MONOTONIC). unsafe: allocates a raw buffer for the libc clock_gettime call.

fnsleep

fn sleep(d: Duration) -> void

Sleeps for the given duration via nanosleep; may wake early on a signal. Returns immediately if d is zero or negative.

fnsystem_time_now

fn system_time_now() -> SystemTime

Returns the current wall-clock time (CLOCK_REALTIME). unsafe: allocates a raw buffer for the libc clock_gettime call.