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:
Dominik Csapak
2020-06-10 12:02:56 +02:00
committed by Wolfgang Bumiller
parent 3d68536fc2
commit e693818afc
7 changed files with 39 additions and 33 deletions

View File

@ -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())
}