Skip to content

Commit

Permalink
Improve Timestamp.seconds_since_unix_epoch()
Browse files Browse the repository at this point in the history
  • Loading branch information
JEnoch committed Sep 15, 2023
1 parent b8f16f1 commit 72867fa
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 13 deletions.
5 changes: 2 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 1 addition & 9 deletions src/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,15 +195,7 @@ impl _Timestamp {
}
#[getter]
pub fn seconds_since_unix_epoch(&self) -> PyResult<f64> {
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())
}
}

Expand Down
3 changes: 2 additions & 1 deletion zenoh/value.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 72867fa

Please sign in to comment.