Skip to content

Commit

Permalink
Permit overflow with wrapping. (#686)
Browse files Browse the repository at this point in the history
  • Loading branch information
YoshikiTakashima authored Jul 29, 2022
1 parent 25ab1cc commit 6c2c75a
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions prost-types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -368,8 +368,13 @@ impl TryFrom<Timestamp> for std::time::SystemTime {
let system_time = if timestamp.seconds >= 0 {
std::time::UNIX_EPOCH.checked_add(time::Duration::from_secs(timestamp.seconds as u64))
} else {
std::time::UNIX_EPOCH
.checked_sub(time::Duration::from_secs((-timestamp.seconds) as u64))
std::time::UNIX_EPOCH.checked_sub(time::Duration::from_secs(
timestamp
.seconds
.checked_neg()
.ok_or(TimestampError::OutOfSystemRange(timestamp.clone()))?
as u64,
))
};

let system_time = system_time.and_then(|system_time| {
Expand Down

0 comments on commit 6c2c75a

Please sign in to comment.