diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-18 02:49:42 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-18 02:49:42 +0000 |
commit | 837b550238aa671a591ccf282dddeab29cadb206 (patch) | |
tree | 914b6b8862bace72bd3245ca184d374b08d8a672 /vendor/time/src/duration.rs | |
parent | Adding debian version 1.70.0+dfsg2-1. (diff) | |
download | rustc-837b550238aa671a591ccf282dddeab29cadb206.tar.xz rustc-837b550238aa671a591ccf282dddeab29cadb206.zip |
Merging upstream version 1.71.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/time/src/duration.rs')
-rw-r--r-- | vendor/time/src/duration.rs | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/vendor/time/src/duration.rs b/vendor/time/src/duration.rs index f8d916f45..47c3f1516 100644 --- a/vendor/time/src/duration.rs +++ b/vendor/time/src/duration.rs @@ -326,7 +326,10 @@ impl Duration { if seconds.is_nan() { crate::expect_failed("passed NaN to `time::Duration::seconds_f64`"); } - Self::new_unchecked(seconds as _, ((seconds % 1.) * 1_000_000_000.) as _) + let seconds_truncated = seconds as i64; + // This only works because we handle the overflow condition above. + let nanoseconds = ((seconds - seconds_truncated as f64) * 1_000_000_000.) as i32; + Self::new_unchecked(seconds_truncated, nanoseconds) } /// Creates a new `Duration` from the specified number of seconds represented as `f32`. @@ -343,7 +346,10 @@ impl Duration { if seconds.is_nan() { crate::expect_failed("passed NaN to `time::Duration::seconds_f32`"); } - Self::new_unchecked(seconds as _, ((seconds % 1.) * 1_000_000_000.) as _) + let seconds_truncated = seconds as i64; + // This only works because we handle the overflow condition above. + let nanoseconds = ((seconds - seconds_truncated as f32) * 1_000_000_000.) as i32; + Self::new_unchecked(seconds_truncated, nanoseconds) } /// Create a new `Duration` with the given number of milliseconds. |