Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Timestamp.get_time and improve Timestamp.seconds_since_unix_epoch #111

Merged
merged 3 commits into from
Sep 18, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.

14 changes: 5 additions & 9 deletions src/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,16 +194,12 @@ impl _Timestamp {
}
}
#[getter]
pub fn get_time(&self) -> PyResult<u64> {
JEnoch marked this conversation as resolved.
Show resolved Hide resolved
Ok(self.0.get_time().0)
}
#[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
9 changes: 8 additions & 1 deletion zenoh/value.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,18 @@ class Timestamp(_Timestamp):
def _upgrade_(this: _Timestamp) -> 'Timestamp':
return _Timestamp.__new__(Timestamp, this)
@property
def get_time(self) -> int:
"""
Returns the time part, as generated by the Zenoh HLC in NTP64 format (See https://datatracker.ietf.org/doc/html/rfc5905#section-6).
"""
return super().time
@property
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
Loading