rust_web_server/ext/date_time_ext/
mod.rs1use std::time::{SystemTime, UNIX_EPOCH};
2
3#[cfg(test)]
4mod tests;
5
6pub struct DateTimeExt;
7
8impl DateTimeExt {
9 pub fn _now_unix_epoch_nanos() -> u128 {
10 let now = SystemTime::now();
11 let nanos = DateTimeExt::_system_time_to_unix_nanos(now);
12 nanos
13 }
14
15 pub fn _system_time_to_unix_nanos(system_time: SystemTime) -> u128 {
16 let boxed_duration = system_time.duration_since(UNIX_EPOCH);
17 if boxed_duration.is_err() {
18 eprintln!("unable to get duration from system time {}", boxed_duration.err().unwrap());
19 let nanos = 0 as u128;
20 return nanos
21 }
22
23 let nanos = boxed_duration.unwrap().as_nanos();
24 nanos
25 }
26
27}