pub trait Clock: Send + Sync {
// Required method
fn millis(&self) -> i64;
// Provided method
fn time(&self) -> DateTime<Utc> { ... }
}Expand description
A trait representing a clock that provides UTC time.
This is the base trait for all clock implementations. It provides methods
to get the current time as a Unix timestamp (milliseconds) or as a
DateTime<Utc> object.
All methods return UTC time only. For timezone support, see
ZonedClock.
§Thread Safety
All implementations must be Send + Sync to ensure thread safety.
§Examples
use prism3_clock::{Clock, SystemClock};
let clock = SystemClock::new();
let timestamp = clock.millis();
let time = clock.time();
println!("Current time: {}", time);§Author
Haixing Hu
Required Methods§
Sourcefn millis(&self) -> i64
fn millis(&self) -> i64
Returns the current time as a Unix timestamp in milliseconds (UTC).
The timestamp represents the number of milliseconds since the Unix epoch (1970-01-01 00:00:00 UTC).
§Returns
The current time as milliseconds since the Unix epoch.
§Examples
use prism3_clock::{Clock, SystemClock};
let clock = SystemClock::new();
let millis = clock.millis();
assert!(millis > 0);Provided Methods§
Sourcefn time(&self) -> DateTime<Utc>
fn time(&self) -> DateTime<Utc>
Returns the current time as a DateTime<Utc>.
This method has a default implementation that constructs a
DateTime<Utc> from the result of millis().
§Returns
The current time as a DateTime<Utc> object.
§Examples
use prism3_clock::{Clock, SystemClock};
let clock = SystemClock::new();
let time = clock.time();
println!("Current time: {}", time);