tinymist_std/
time.rs

1//! Cross platform time utilities.
2
3pub use std::time::SystemTime as Time;
4pub use web_time::{Duration, Instant};
5
6/// Returns the current system time (UTC+0).
7#[cfg(any(feature = "system", feature = "web"))]
8pub fn now() -> Time {
9    #[cfg(not(all(target_family = "wasm", target_os = "unknown")))]
10    {
11        Time::now()
12    }
13    #[cfg(all(target_family = "wasm", target_os = "unknown"))]
14    {
15        use web_time::web::SystemTimeExt;
16        web_time::SystemTime::now().to_std()
17    }
18}
19
20/// Returns a dummy time on environments that do not support time.
21#[cfg(not(any(feature = "system", feature = "web")))]
22pub fn now() -> Time {
23    Time::UNIX_EPOCH
24}