From 72867fa7d8321430f24c534cd86efcdfc1406ddd Mon Sep 17 00:00:00 2001 From: Julien Enoch Date: Fri, 15 Sep 2023 17:05:54 +0200 Subject: [PATCH] Improve Timestamp.seconds_since_unix_epoch() --- Cargo.lock | 5 ++--- src/value.rs | 10 +--------- zenoh/value.py | 3 ++- 3 files changed, 5 insertions(+), 13 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 25cc7254..7c778d22 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2251,11 +2251,10 @@ checksum = "9e79c4d996edb816c91e4308506774452e55e95c3c9de07b6729e17e15a5ef81" [[package]] name = "uhlc" -version = "0.6.0" +version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af1438496174a601a35fb41bf9bc408e47384b1df52ddc1252e75ef0ab811322" +checksum = "d1eadef1fa26cbbae1276c46781e8f4d888bdda434779c18ae6c2a0e69991885" dependencies = [ - "hex", "humantime", "lazy_static", "log", diff --git a/src/value.rs b/src/value.rs index 0432412f..26ae8721 100644 --- a/src/value.rs +++ b/src/value.rs @@ -195,15 +195,7 @@ impl _Timestamp { } #[getter] pub fn seconds_since_unix_epoch(&self) -> PyResult { - match self - .0 - .get_time() - .to_system_time() - .duration_since(std::time::UNIX_EPOCH) - { - Ok(o) => Ok(o.as_secs_f64()), - Err(e) => Err(e.to_pyerr()), - } + Ok(self.0.get_time().as_secs_f64()) } } diff --git a/zenoh/value.py b/zenoh/value.py index 5c33685f..d1bcd723 100644 --- a/zenoh/value.py +++ b/zenoh/value.py @@ -118,7 +118,8 @@ def seconds_since_unix_epoch(self) -> float: """ Returns the number of seconds since the Unix Epoch. - You shouldn't use this for comparison though, and rely on comparison operators between members of this class. + Considering the large number of seconds since the Unix Epoch, the precision of the resulting f64 is in the order of microseconds. + Therefore, it should not be used for comparison. Directly comparing Timestamp objects is preferable. """ return super().seconds_since_unix_epoch