-
-
Notifications
You must be signed in to change notification settings - Fork 282
Export days_in_year_month
#219
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
Comments
The current implementation is for internal usage, so valid data is assumed. If I were to make this public, it would have to have additional checks for the bounds in both Documentation would also have to be added, but that wouldn't be difficult. I'll have to think about this more, but it would require some fiddling around to make things work. |
To address the concerns about valid data we could rather implement /// Get the number of days in the month of a given year.
pub const fn try_days_in_year_month(year: i32, month: u8) -> Result<u8, ComponentRangeError> {
...
} |
Like I said, I'll take a look into things. I'm just not 100% on whether this would be necessary if the internal structure of With regard to a |
Ok. I'll wait for your comments. |
Just to comment about my actual need. I was trying to generate arbitrary but valid instances of #cfg(test)
mod test {
#[derive(Debug, Clone)]
struct DateBuilder {
year: i32,
month: u8,
day: u8
}
impl Arbitrary for DateBuilder {
fn arbitrary<G: Gen>(g: &mut G) -> Self {
let year: i32 = g.gen_range(-100_000, 100_001);
let month: u8 = g.gen_range(1, 13);
let day: u8 = g.gen_range(1, days_in_year_month(year, month) + 1);
DateBuilder{year: year, month: month, day: day}
}
}
impl DateBuilder {
fn get_date(&self) -> Date {
Date::try_from_ymd(self.year, self.month, self.day).unwrap()
}
}
// etc...
} You may notice that I needed to use |
Is there any particular reason you're using quickcheck over proptest? At least from this issue, it seems like proptest would be preferred in the vast majority of cases. I could conceivably implement |
Plain ignorance. I didn't know about proptest. Now that you have introduced it to me, I think I will like it better (I have extensively used Hypothesis for Python). I searched for 'quickcheck' because that's the "original" Haskell implementation. |
Going ahead with implementation of |
Great! Looking forward a new release of time. ;) I'm reading the docs of proptest. Thanks for the tip on composing |
As the provided use case can be accomplished other ways and support for the rand crate is now on master, closing this. |
This function is currently private, but it can be useful for validation purposes and arbitrary (quickcheck generation of valid dates.
The text was updated successfully, but these errors were encountered: