mprober_lib/btime/
mod.rs

1use std::sync::Once;
2
3use chrono::prelude::*;
4
5use crate::uptime::get_uptime;
6
7/// Get the btime (boot time) by subtract the current uptime from the current unix epoch timestamp.
8///
9/// ```rust
10/// use mprober_lib::btime;
11///
12/// let btime = btime::get_btime();
13///
14/// println!("{btime}");
15/// ```
16#[inline]
17pub fn get_btime() -> DateTime<Utc> {
18    static START: Once = Once::new();
19    static mut BTIME: Option<DateTime<Utc>> = None;
20
21    unsafe {
22        START.call_once(|| BTIME = Some(get_uptime().unwrap().get_btime()));
23
24        BTIME.unwrap()
25    }
26}