New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Optionally implement Arbitrary for Naive{Date,Time,DateTime} #559
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -190,6 +190,15 @@ pub struct NaiveTime { | |||
frac: u32, | ||||
} | ||||
|
||||
#[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_400)?; | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If I understand correctly these ranges should not be inclusive... a day has up to 86399 seconds, and See Line 391 in 1281ce0
|
||||
let frac = u.int_in_range(0..=2_000_000_000)?; | ||||
Ok(NaiveTime { secs, frac }) | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This feels like something that might be better to use And yeah, a secs of 86_400 will be rejected. |
||||
} | ||||
} | ||||
|
||||
impl NaiveTime { | ||||
/// Makes a new `NaiveTime` from hour, minute and second. | ||||
/// | ||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we construct the YearFlags and determine the exact ndays in the year so constructing the date wouldn't fail
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That doesn't seem like it makes a particularly large difference?