Skip to content
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

Allow generating any random DateTime<Tz> where Tz: Timezone + Dummy #123

Merged
merged 2 commits into from
Feb 7, 2023

Conversation

kyrias
Copy link
Contributor

@kyrias kyrias commented Feb 6, 2023

This means that any additional timezones will be supported automatically just as long as Dummy<Faker> is implemented for them.

This also updates the chrono-tz dependency to the newest major version.

@kyrias
Copy link
Contributor Author

kyrias commented Feb 6, 2023

One thing I realized is that it would be good if there was some way to give the fake crate some form of constraints, f.ex. limiting which years it'll try to generate datetimes for. Not sure how one would go about implementing that into the current API though. Maybe having some kind of AnyMap in the Faker struct that relevant constraints could be retrieved from by the Dummy implementation?

@cksac
Copy link
Owner

cksac commented Feb 6, 2023

you can use different config struct e.g. DateOnYear(String) and implement Dummy.

impl Dummy<Faker> for DateTime<Utc> {
impl Dummy<Faker> for Utc {
fn dummy_with_rng<R: Rng + ?Sized>(_: &Faker, _: &mut R) -> Self {
Utc
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is use of this impl?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without this implementation there would be no implementation of Dummy<Faker> for DateTime<Utc>.

@kyrias
Copy link
Contributor Author

kyrias commented Feb 6, 2023

you can use different config struct e.g. DateOnYear(String) and implement Dummy.

Oh I didn't realize that you could specify an override type with #[dummy(faker = ...)]. It would be useful if the docs.rs docs were built with the features enabled. :)

The downside with that approach is that it seems like you'd have to reimplement the entire Dummy implementation for every possible kind of constraint rather than being able to have a single implementation for the type, but this is workable I guess.

@cksac cksac merged commit 6fc6788 into cksac:master Feb 7, 2023
@kyrias kyrias deleted the chrono-tz-datetime branch February 7, 2023 13:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants