pub struct Timestamp {
pub time: Option<Time>,
}
Expand description
A newtype wrapper over Option<Time>
to keep track of
IBC packet timeout.
We use an explicit Option
type to distinguish this when converting between
a u64
value and a raw timestamp. In protocol buffer, the timestamp is
represented as a u64
Unix timestamp in nanoseconds, with 0 representing the absence
of timestamp.
Fields§
§time: Option<Time>
Implementations§
Source§impl Timestamp
impl Timestamp
Sourcepub fn from_nanoseconds(
nanoseconds: u64,
) -> Result<Timestamp, ParseTimestampError>
pub fn from_nanoseconds( nanoseconds: u64, ) -> Result<Timestamp, ParseTimestampError>
The IBC protocol represents timestamps as u64 Unix timestamps in nanoseconds.
A protocol value of 0 indicates that the timestamp is not set. In this case, our domain type takes the value of None.
Sourcepub fn now() -> Timestamp
Available on crate feature std
only.
pub fn now() -> Timestamp
std
only.Returns a Timestamp
representation of the current time.
Sourcepub fn duration_since(&self, other: &Timestamp) -> Option<Duration>
pub fn duration_since(&self, other: &Timestamp) -> Option<Duration>
Computes the duration difference of another Timestamp
from the current one.
Returns the difference in time as an core::time::Duration
.
Returns None
if the other Timestamp
is more advanced
than the current or if either of the Timestamp
s is not set.
Sourcepub fn as_nanoseconds(&self) -> u64
👎Deprecated since 0.9.1: use nanoseconds
instead
pub fn as_nanoseconds(&self) -> u64
nanoseconds
insteadConvert a Timestamp
to u64
value in nanoseconds. If no timestamp
is set, the result is 0.
Sourcepub fn nanoseconds(self) -> u64
pub fn nanoseconds(self) -> u64
Convert a Timestamp
to u64
value in nanoseconds. If no timestamp
is set, the result is 0.
let max = u64::MAX;
let tx = Timestamp::from_nanoseconds(max).unwrap();
let utx = tx.nanoseconds();
assert_eq!(utx, max);
let min = u64::MIN;
let ti = Timestamp::from_nanoseconds(min).unwrap();
let uti = ti.nanoseconds();
assert_eq!(uti, min);
let tz = Timestamp::default();
let utz = tz.nanoseconds();
assert_eq!(utz, 0);
Sourcepub fn into_datetime(self) -> Option<OffsetDateTime>
pub fn into_datetime(self) -> Option<OffsetDateTime>
Convert a Timestamp
to an optional OffsetDateTime
Sourcepub fn into_tm_time(self) -> Option<Time>
pub fn into_tm_time(self) -> Option<Time>
Convert a Timestamp
to an optional tendermint::Time
Sourcepub fn check_expiry(&self, other: &Timestamp) -> Expiry
pub fn check_expiry(&self, other: &Timestamp) -> Expiry
Checks whether the timestamp has expired when compared to the
other
timestamp. Returns an Expiry
result.