summaryrefslogtreecommitdiff
path: root/profcollectd/libprofcollectd/report.rs
diff options
context:
space:
mode:
Diffstat (limited to 'profcollectd/libprofcollectd/report.rs')
-rw-r--r--profcollectd/libprofcollectd/report.rs11
1 files changed, 10 insertions, 1 deletions
diff --git a/profcollectd/libprofcollectd/report.rs b/profcollectd/libprofcollectd/report.rs
index c37993b7..a67d500b 100644
--- a/profcollectd/libprofcollectd/report.rs
+++ b/profcollectd/libprofcollectd/report.rs
@@ -23,7 +23,7 @@ use std::fs::{self, File, Permissions};
use std::io::{Read, Write};
use std::os::unix::fs::PermissionsExt;
use std::path::{Path, PathBuf};
-use std::time::SystemTime;
+use std::time::{Duration, SystemTime};
use uuid::v1::{Context, Timestamp};
use uuid::Uuid;
use zip::write::FileOptions;
@@ -82,3 +82,12 @@ fn get_report_filename(node_id: &MacAddr6) -> Result<String> {
let uuid = Uuid::new_v1(ts, &node_id.as_bytes())?;
Ok(uuid.to_string())
}
+
+/// Get report creation timestamp through its filename (version 1 UUID).
+pub fn get_report_ts(filename: &str) -> Result<SystemTime> {
+ let uuid_ts = Uuid::parse_str(filename)?
+ .to_timestamp()
+ .ok_or_else(|| anyhow!("filename is not a valid V1 UUID."))?
+ .to_unix();
+ Ok(SystemTime::UNIX_EPOCH + Duration::new(uuid_ts.0, uuid_ts.1))
+}