mirror of
https://github.com/EFForg/rayhunter.git
synced 2026-05-31 10:13:35 -07:00
26 lines
756 B
Rust
26 lines
756 B
Rust
//! Global clock offset for adjusting timestamps.
|
|
//!
|
|
//! This module provides a global clock offset that can be used to adjust
|
|
//! timestamps when the device's system clock is incorrect. The offset is
|
|
//! stored in memory and is not persisted across restarts.
|
|
|
|
use chrono::{DateTime, Local, TimeDelta};
|
|
use std::sync::RwLock;
|
|
|
|
static CLOCK_OFFSET: RwLock<TimeDelta> = RwLock::new(TimeDelta::zero());
|
|
|
|
/// Get the current clock offset.
|
|
fn get_offset() -> TimeDelta {
|
|
*CLOCK_OFFSET.read().unwrap()
|
|
}
|
|
|
|
/// Set the clock offset.
|
|
pub fn set_offset(offset: TimeDelta) {
|
|
*CLOCK_OFFSET.write().unwrap() = offset;
|
|
}
|
|
|
|
/// Get the current adjusted time (system time + offset).
|
|
pub fn get_adjusted_now() -> DateTime<Local> {
|
|
Local::now() + get_offset()
|
|
}
|