leptos-use 0.19.2

Collection of essential Leptos utilities inspired by React-Use / VueUse
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
use cfg_if::cfg_if;

/// SSR safe `Date.now()`.
#[inline(always)]
pub(crate) fn now() -> f64 {
    cfg_if! { if #[cfg(feature = "ssr")] {
        use std::time::{SystemTime, UNIX_EPOCH};

        // If the system clock is at or before the Unix epoch we degrade to 0
        // instead of panicking.
        SystemTime::now()
            .duration_since(UNIX_EPOCH)
            .unwrap_or_default()
            .as_millis() as f64
    } else {
        js_sys::Date::now()
    }}
}