Skip to content

Commit

Permalink
fix underflow when running cargo wasi test
Browse files Browse the repository at this point in the history
  • Loading branch information
dylanhart committed Feb 3, 2024
1 parent c220598 commit 673315b
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,11 +168,14 @@ mod tests {

#[test]
fn truncates_at_unix_epoch() {
let before_epoch = SystemTime::UNIX_EPOCH - Duration::from_secs(100);
assert!(before_epoch < SystemTime::UNIX_EPOCH);
assert_eq!(
Ulid::from_datetime(before_epoch).datetime(),
SystemTime::UNIX_EPOCH
);
if let Some(before_epoch) = SystemTime::UNIX_EPOCH.checked_sub(Duration::from_secs(100)) {
assert!(before_epoch < SystemTime::UNIX_EPOCH);
assert_eq!(
Ulid::from_datetime(before_epoch).datetime(),
SystemTime::UNIX_EPOCH
);
} else {
// Prior dates are not representable (e.g. wasm32-wasi)
}
}
}

0 comments on commit 673315b

Please sign in to comment.