Skip to content

unix_now

The current time as whole seconds since the Unix epoch.

use helpers4::time::unix_now;

Cargo feature time (enabled by default). To compile only this module:

cargo add helpers4 --no-default-features --features time

or in Cargo.toml:

[dependencies]
helpers4 = { version = "0.0.5", default-features = false, features = ["time"] }
pub fn unix_now() -> Result<u64, ClockError>

Result<u64, ClockError>Ok on success, otherwise an Err: see Errors.

ClockError when the system clock is set before 1970. Do not turn that into 0: a token expiry checked against 0 would look valid forever.

use helpers4::time::unix_now;

let now = unix_now()?;
assert!(now > 1_700_000_000); // after November 2023

The system clock is set before the Unix epoch (1970-01-01T00:00:00Z).

Returned instead of a silent 0: an expiry comparison against 0 would treat every token as still valid.

use helpers4::time::ClockError;

pub struct ClockError { /* private fields */ }
pub fn behind(&self) -> Duration

How far before the epoch the clock is.

Returns

Duration — How far in the past the system clock reported, relative to the Unix epoch.

src/time/unix_now.rs