diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-30 03:57:19 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-30 03:57:19 +0000 |
commit | a0b8f38ab54ac451646aa00cd5e91b6c76f22a84 (patch) | |
tree | fc451898ccaf445814e26b46664d78702178101d /vendor/time/src/rand.rs | |
parent | Adding debian version 1.71.1+dfsg1-2. (diff) | |
download | rustc-a0b8f38ab54ac451646aa00cd5e91b6c76f22a84.tar.xz rustc-a0b8f38ab54ac451646aa00cd5e91b6c76f22a84.zip |
Merging upstream version 1.72.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/time/src/rand.rs')
-rw-r--r-- | vendor/time/src/rand.rs | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/vendor/time/src/rand.rs b/vendor/time/src/rand.rs index 8afefe507..e5181f9bd 100644 --- a/vendor/time/src/rand.rs +++ b/vendor/time/src/rand.rs @@ -3,15 +3,16 @@ use rand::distributions::{Distribution, Standard}; use rand::Rng; +use crate::convert::*; use crate::{Date, Duration, Month, OffsetDateTime, PrimitiveDateTime, Time, UtcOffset, Weekday}; impl Distribution<Time> for Standard { fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> Time { Time::__from_hms_nanos_unchecked( - rng.gen_range(0..24), - rng.gen_range(0..60), - rng.gen_range(0..60), - rng.gen_range(0..1_000_000_000), + rng.gen_range(0..Hour.per(Day)), + rng.gen_range(0..Minute.per(Hour)), + rng.gen_range(0..Second.per(Minute)), + rng.gen_range(0..Nanosecond.per(Second)), ) } } @@ -26,11 +27,11 @@ impl Distribution<Date> for Standard { impl Distribution<UtcOffset> for Standard { fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> UtcOffset { - let seconds = rng.gen_range(-86399..=86399); + let seconds = rng.gen_range(-(Second.per(Day) as i32 - 1)..=(Second.per(Day) as i32 - 1)); UtcOffset::__from_hms_unchecked( - (seconds / 3600) as _, - ((seconds % 3600) / 60) as _, - (seconds % 60) as _, + (seconds / Second.per(Hour) as i32) as _, + ((seconds % Second.per(Hour) as i32) / Minute.per(Hour) as i32) as _, + (seconds % Second.per(Minute) as i32) as _, ) } } |