gilrs_core/
utils.rs

1use std::time::SystemTime;
2
3/// Returns true if nth bit in array is 1.
4#[allow(dead_code)]
5pub(crate) fn test_bit(n: u16, array: &[u8]) -> bool {
6    (array[(n / 8) as usize] >> (n % 8)) & 1 != 0
7}
8
9#[cfg(not(target_arch = "wasm32"))]
10pub fn time_now() -> SystemTime {
11    SystemTime::now()
12}
13
14#[cfg(target_arch = "wasm32")]
15pub fn time_now() -> SystemTime {
16    use js_sys::Date;
17    use std::time::Duration;
18
19    let offset = Duration::from_millis(Date::now() as u64);
20    SystemTime::UNIX_EPOCH + offset
21}