Skip to content

Commit f335c20

Browse files
committed
Repro duration_since regression from issue 146228
1 parent 52618eb commit f335c20

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

library/std/tests/time.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,3 +227,19 @@ fn big_math() {
227227
check(instant.checked_add(Duration::from_secs(100)), Instant::checked_sub);
228228
check(instant.checked_add(Duration::from_secs(i64::MAX as _)), Instant::checked_sub);
229229
}
230+
231+
#[test]
232+
#[cfg(unix)]
233+
fn system_time_duration_since_max_range_on_unix() {
234+
// Repro regression https://github.com/rust-lang/rust/issues/146228
235+
236+
// Min and max values of `SystemTime` on Unix.
237+
let min = SystemTime::UNIX_EPOCH - (Duration::new(i64::MAX as u64 + 1, 0));
238+
let max = SystemTime::UNIX_EPOCH + (Duration::new(i64::MAX as u64, 999_999_999));
239+
240+
let delta_a = max.duration_since(min).expect("duration_since overflow");
241+
let delta_b = min.duration_since(max).err().expect("duration_since overflow").duration();
242+
243+
assert_eq!(Duration::MAX, delta_a);
244+
assert_eq!(Duration::MAX, delta_b);
245+
}

0 commit comments

Comments
 (0)