Skip to content

Commit

Permalink
improve_estimate_instant
Browse files Browse the repository at this point in the history
  • Loading branch information
damip committed Apr 19, 2023
1 parent b1ee23e commit e1323db
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions massa-time/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,13 +260,13 @@ impl MassaTime {
/// ) < std::time::Duration::from_millis(10))
/// ```
pub fn estimate_instant(self) -> Result<Instant, TimeError> {
let (cur_timestamp, cur_instant): (MassaTime, Instant) =
(MassaTime::now()?, Instant::now());
cur_instant
.checked_add(self.to_duration())
.ok_or(TimeError::TimeOverflowError)?
.checked_sub(cur_timestamp.to_duration())
.ok_or(TimeError::TimeOverflowError)
let (cur_timestamp, cur_instant) = (MassaTime::now()?, Instant::now());
if self >= cur_timestamp {
cur_instant.checked_add(self.saturating_sub(cur_timestamp).to_duration())
} else {
cur_instant.checked_sub(cur_timestamp.saturating_sub(self).to_duration())
}
.ok_or(TimeError::TimeOverflowError)
}

/// ```
Expand Down

0 comments on commit e1323db

Please sign in to comment.