summaryrefslogtreecommitdiffstats
path: root/vendor/time/src/rand.rs
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/time/src/rand.rs')
-rw-r--r--vendor/time/src/rand.rs17
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 _,
)
}
}