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

Return Error If Overflow #686

Merged
merged 3 commits into from Jul 29, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 7 additions & 2 deletions prost-types/src/lib.rs
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