1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
//! Wasm32-safe wall-clock helpers.
//!
//! `std::time::SystemTime::now()` is not implemented on
//! `wasm32-unknown-unknown` — calling it panics at runtime (it traps with
//! `unreachable!()` from libstd before returning a `Result`, so callers
//! can't even `unwrap_or` their way out). That blocks any downstream that
//! drives BSV protocol code from inside a Cloudflare Worker or similar
//! `wasm32-unknown-unknown` host.
//!
//! These helpers cfg-gate the implementation:
//!
//! - Native (default): delegate to `std::time::SystemTime::now()` exactly
//! as before. Native callers see zero behavioral change.
//! - `wasm32-unknown-unknown` with the `wasm` feature: use
//! `js_sys::Date::now()`, which returns milliseconds since the Unix
//! epoch as an `f64` and is available in every JS host (browsers,
//! Node.js, Cloudflare Workers, Deno). Sub-millisecond precision is
//! lost — `js_sys::Date::now()` is millisecond-quantized — but
//! `SystemTime` is unreachable on this target so there is no
//! higher-precision alternative without pulling in a JS-specific dep
//! like `web-sys`'s `Performance` API.
//!
//! All helpers return monotonically-non-decreasing values relative to
//! the Unix epoch; callers that previously computed
//! `SystemTime::now().duration_since(UNIX_EPOCH).unwrap_or_default()`
//! can be ported by calling [`duration_since_unix_epoch`] directly.
use Duration;
/// Returns the wall-clock duration since the Unix epoch (1970-01-01 UTC).
///
/// Returns `Duration::ZERO` if the system clock is set before the Unix
/// epoch (a near-impossible edge case on real deployments, but preserved
/// so call sites that previously used `unwrap_or_default()` keep the same
/// behavior).
// Not used by every feature combination.
pub
/// Returns the wall-clock duration since the Unix epoch (1970-01-01 UTC).
// Not used by every feature combination.
pub
/// Returns current wall-clock time in milliseconds since the Unix epoch.
///
/// Equivalent to `duration_since_unix_epoch().as_millis() as u64`.
// Not used by every feature combination.
pub
/// Returns current wall-clock time in seconds since the Unix epoch.
///
/// Equivalent to `duration_since_unix_epoch().as_secs()`.
// Not used by every feature combination.
pub