Skip to content

Commit

Permalink
Add check for invalid concrete time dates
Browse files Browse the repository at this point in the history
  • Loading branch information
gshuflin committed Jul 14, 2020
1 parent 2fd1955 commit 1781198
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/rust/engine/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/rust/engine/concrete_time/Cargo.toml
Expand Up @@ -9,3 +9,4 @@ publish = false
protobuf = { version = "2.0.6", features = ["with-bytes"] }
serde_derive = "1.0.98"
serde = "1.0.98"
log = "0.4"
9 changes: 8 additions & 1 deletion src/rust/engine/concrete_time/src/lib.rs
Expand Up @@ -102,7 +102,14 @@ impl TimeSpan {
end: &std::time::SystemTime,
) -> TimeSpan {
let start = Self::since_epoch(start);
let duration = Self::since_epoch(end) - start;
let end = Self::since_epoch(end);
let duration = match end.checked_sub(start) {
Some(d) => d,
None => {
log::warn!("Invalid TimeSpan - start: {:?}, end: {:?}", start, end);
std::time::Duration::new(0, 0)
}
};
TimeSpan {
start: start.into(),
duration: duration.into(),
Expand Down

0 comments on commit 1781198

Please sign in to comment.