Skip to content

Commit 202af6c

Browse files
committed
Don't generate leap seconds that are not 60 in NaiveTime's Arbitrary impl
1 parent 60283ab commit 202af6c

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/naive/time/mod.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -208,9 +208,14 @@ pub struct NaiveTime {
208208
#[cfg(feature = "arbitrary")]
209209
impl arbitrary::Arbitrary<'_> for NaiveTime {
210210
fn arbitrary(u: &mut arbitrary::Unstructured) -> arbitrary::Result<NaiveTime> {
211-
let secs = u.int_in_range(0..=86_399)?;
212-
let nano = u.int_in_range(0..=1_999_999_999)?;
213-
let time = NaiveTime::from_num_seconds_from_midnight_opt(secs, nano)
211+
let mins = u.int_in_range(0..=1439)?;
212+
let mut secs = u.int_in_range(0..=60)?;
213+
let mut nano = u.int_in_range(0..=999_999_999)?;
214+
if secs == 60 {
215+
secs = 59;
216+
nano += 1_000_000_000;
217+
}
218+
let time = NaiveTime::from_num_seconds_from_midnight_opt(mins * 60 + secs, nano)
214219
.expect("Could not generate a valid chrono::NaiveTime. It looks like implementation of Arbitrary for NaiveTime is erroneous.");
215220
Ok(time)
216221
}

0 commit comments

Comments
 (0)