From 202af6cfda9bfdb195dc96377fcdeee7ed024b65 Mon Sep 17 00:00:00 2001 From: Paul Dicker Date: Tue, 12 Sep 2023 17:07:34 +0200 Subject: [PATCH] Don't generate leap seconds that are not 60 in NaiveTime's Arbitrary impl --- src/naive/time/mod.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/naive/time/mod.rs b/src/naive/time/mod.rs index e9e2e02970..88e9d50ce8 100644 --- a/src/naive/time/mod.rs +++ b/src/naive/time/mod.rs @@ -208,9 +208,14 @@ pub struct NaiveTime { #[cfg(feature = "arbitrary")] impl arbitrary::Arbitrary<'_> for NaiveTime { fn arbitrary(u: &mut arbitrary::Unstructured) -> arbitrary::Result { - let secs = u.int_in_range(0..=86_399)?; - let nano = u.int_in_range(0..=1_999_999_999)?; - let time = NaiveTime::from_num_seconds_from_midnight_opt(secs, nano) + let mins = u.int_in_range(0..=1439)?; + let mut secs = u.int_in_range(0..=60)?; + let mut nano = u.int_in_range(0..=999_999_999)?; + if secs == 60 { + secs = 59; + nano += 1_000_000_000; + } + let time = NaiveTime::from_num_seconds_from_midnight_opt(mins * 60 + secs, nano) .expect("Could not generate a valid chrono::NaiveTime. It looks like implementation of Arbitrary for NaiveTime is erroneous."); Ok(time) }