refactor time functions to tools
Signed-off-by: Dominik Csapak <d.csapak@proxmox.com> Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
committed by
Wolfgang Bumiller
parent
3d68536fc2
commit
e693818afc
14
src/tools.rs
14
src/tools.rs
@ -9,6 +9,7 @@ use std::io::{self, BufRead, ErrorKind, Read};
|
||||
use std::os::unix::io::{AsRawFd, RawFd};
|
||||
use std::path::Path;
|
||||
use std::time::Duration;
|
||||
use std::time::{SystemTime, SystemTimeError, UNIX_EPOCH};
|
||||
|
||||
use anyhow::{bail, format_err, Error};
|
||||
use serde_json::Value;
|
||||
@ -609,3 +610,16 @@ pub fn file_get_non_comment_lines<P: AsRef<Path>>(
|
||||
Err(err) => Some(Err(err)),
|
||||
}))
|
||||
}
|
||||
|
||||
pub fn epoch_now() -> Result<Duration, SystemTimeError> {
|
||||
SystemTime::now().duration_since(UNIX_EPOCH)
|
||||
}
|
||||
|
||||
pub fn epoch_now_f64() -> Result<f64, SystemTimeError> {
|
||||
Ok(epoch_now()?.as_secs_f64())
|
||||
}
|
||||
|
||||
pub fn epoch_now_u64() -> Result<u64, SystemTimeError> {
|
||||
Ok(epoch_now()?.as_secs())
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user