Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

fix(timestamp): saturate instant subtraction on underflow

Richie McIlroydb57101ad912
diff --git a/crates/timestamp/src/lib.rs b/crates/timestamp/src/lib.rs
index 80c87c427..9b537fdfe 100644
--- a/crates/timestamp/src/lib.rs
+++ b/crates/timestamp/src/lib.rs
@@ -120,7 +120,7 @@ impl std::ops::Sub<Duration> for Timestamp {
fn sub(self, rhs: Duration) -> Self::Output {
match self {
- Timestamp::Instant(i) => Timestamp::Instant(i.checked_sub(rhs).unwrap()),
+ Timestamp::Instant(i) => Timestamp::Instant(i.checked_sub(rhs).unwrap_or(i)),
Timestamp::SystemTime(t) => Timestamp::SystemTime(t - rhs),
#[cfg(windows)]
Timestamp::PerformanceCounter(c) => Timestamp::PerformanceCounter(c - rhs),