Skip to content

Commit

Permalink
Allows to convert into/from micros_since_epoch:u64 for TimeStamp (#731)
Browse files Browse the repository at this point in the history
  • Loading branch information
mamcx authored Jan 18, 2024
1 parent 9441409 commit ffd22de
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions crates/bindings/src/timestamp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,16 @@ impl Timestamp {
let micros_since_epoch = self.micros_since_epoch.checked_sub(micros)?;
Some(Self { micros_since_epoch })
}

/// Converts the timestamp into the number of microseconds since the UNIX epoch.
pub fn into_micros_since_epoch(self) -> u64 {
self.micros_since_epoch
}

/// Creates a new timestamp from the given number of microseconds since the UNIX epoch.
pub fn from_micros_since_epoch(micros_since_epoch: u64) -> Self {
Self { micros_since_epoch }
}
}

impl Add<Duration> for Timestamp {
Expand All @@ -90,5 +100,5 @@ impl Sub<Duration> for Timestamp {
}

impl_st!([] Timestamp, _ts => spacetimedb_lib::AlgebraicType::U64);
impl_deserialize!([] Timestamp, de => u64::deserialize(de).map(|m| Self { micros_since_epoch: m }));
impl_serialize!([] Timestamp, (self, ser) => self.micros_since_epoch.serialize(ser));
impl_deserialize!([] Timestamp, de => u64::deserialize(de).map(Self::from_micros_since_epoch));
impl_serialize!([] Timestamp, (self, ser) => self.into_micros_since_epoch().serialize(ser));

2 comments on commit ffd22de

@github-actions
Copy link

@github-actions github-actions bot commented on ffd22de Jan 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Benchmarking failed. Please check the workflow run for details.

@github-actions
Copy link

@github-actions github-actions bot commented on ffd22de Jan 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Benchmark results Error when comparing benchmarks:

Caused by:

Please sign in to comment.