diff --git a/src/duration.rs b/src/duration.rs index 91aaeb938..1e67ea78b 100644 --- a/src/duration.rs +++ b/src/duration.rs @@ -201,15 +201,15 @@ impl Duration { // region: constructors /// Create a new `Duration` without checking the validity of the components. pub(crate) const fn new_unchecked(seconds: i64, nanoseconds: i32) -> Self { - if seconds < 0 { - debug_assert!(nanoseconds <= 0); - debug_assert!(nanoseconds > -1_000_000_000); - } else if seconds > 0 { - debug_assert!(nanoseconds >= 0); - debug_assert!(nanoseconds < 1_000_000_000); - } else { - debug_assert!(nanoseconds.unsigned_abs() < 1_000_000_000); - } + // if seconds < 0 { + // debug_assert!(nanoseconds <= 0); + // debug_assert!(nanoseconds > -1_000_000_000); + // } else if seconds > 0 { + // debug_assert!(nanoseconds >= 0); + // debug_assert!(nanoseconds < 1_000_000_000); + // } else { + // debug_assert!(nanoseconds.unsigned_abs() < 1_000_000_000); + // } Self { seconds, diff --git a/src/time.rs b/src/time.rs index 7ef6fa87c..added70f5 100644 --- a/src/time.rs +++ b/src/time.rs @@ -748,7 +748,8 @@ impl Sub for Time { cascade!(nanosecond_diff in 0..1_000_000_000 => second_diff); - Duration::new_unchecked( + // TODO(jhpratt) use `new_unchecked` and ensure validity + Duration::new( hour_diff as i64 * 3_600 + minute_diff as i64 * 60 + second_diff as i64, nanosecond_diff, ) diff --git a/tests/integration/time.rs b/tests/integration/time.rs index 5f8e4231d..54b8485b1 100644 --- a/tests/integration/time.rs +++ b/tests/integration/time.rs @@ -340,3 +340,12 @@ fn ordering() { assert!(time!(12:00) > time!(11:00)); assert_eq!(time!(0:00), time!(0:00)); } + +#[test] +fn issue_481() { + assert_eq!(time!(0:00) - time!(01:00:00.1), (-3600.1).seconds()); + assert_eq!( + time!(0:00) - time!(23:59:59.999_999_999), + (-86_399.999_999_999).seconds() + ); +}