Skip to content

Commit

Permalink
Don't generate leap seconds that are not 60 in NaiveTime's Arbitrary …
Browse files Browse the repository at this point in the history
…impl
  • Loading branch information
pitdicker committed Sep 12, 2023
1 parent 60283ab commit 202af6c
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/naive/time/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,14 @@ pub struct NaiveTime {
#[cfg(feature = "arbitrary")]
impl arbitrary::Arbitrary<'_> for NaiveTime {
fn arbitrary(u: &mut arbitrary::Unstructured) -> arbitrary::Result<NaiveTime> {
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)
}
Expand Down

0 comments on commit 202af6c

Please sign in to comment.