Skip to main content

Clock

Trait Clock 

Source
pub trait Clock:
    Send
    + Sync
    + 'static {
    // Required method
    fn now(&self) -> Timestamp;

    // Provided methods
    fn now_in(&self, tz: &TimeZone) -> Zoned { ... }
    fn today_in(&self, tz: &TimeZone) -> Date { ... }
    fn now_unix_millis(&self) -> i64 { ... }
}
Expand description

Wall-clock readouts. Single port for “what time is it?” across all surfaces.

now() is the only required method; the zone-aware readouts derive from it via jiff (tzdb available on every arm, including wasm via the bundled db).

Required Methods§

Source

fn now(&self) -> Timestamp

The current instant. The one method an arm implements.

Provided Methods§

Source

fn now_in(&self, tz: &TimeZone) -> Zoned

The current instant as a wall-clock reading in tz.

Source

fn today_in(&self, tz: &TimeZone) -> Date

Today’s calendar date in tz — the date a person in that zone reads off their calendar, which differs from the UTC date near midnight.

Source

fn now_unix_millis(&self) -> i64

The current instant as Unix epoch milliseconds.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl Clock for FrozenClock

Available on crate feature mock only.
Source§

impl Clock for MockClock

Available on crate feature mock only.
Source§

impl Clock for WallClock

Available on crate feature native only.