Skip to content

Commit 673315b

Browse files
committed
fix underflow when running cargo wasi test
1 parent c220598 commit 673315b

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

src/time.rs

+9-6
Original file line numberDiff line numberDiff line change
@@ -168,11 +168,14 @@ mod tests {
168168

169169
#[test]
170170
fn truncates_at_unix_epoch() {
171-
let before_epoch = SystemTime::UNIX_EPOCH - Duration::from_secs(100);
172-
assert!(before_epoch < SystemTime::UNIX_EPOCH);
173-
assert_eq!(
174-
Ulid::from_datetime(before_epoch).datetime(),
175-
SystemTime::UNIX_EPOCH
176-
);
171+
if let Some(before_epoch) = SystemTime::UNIX_EPOCH.checked_sub(Duration::from_secs(100)) {
172+
assert!(before_epoch < SystemTime::UNIX_EPOCH);
173+
assert_eq!(
174+
Ulid::from_datetime(before_epoch).datetime(),
175+
SystemTime::UNIX_EPOCH
176+
);
177+
} else {
178+
// Prior dates are not representable (e.g. wasm32-wasi)
179+
}
177180
}
178181
}

0 commit comments

Comments
 (0)