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

New 'date' provider #95

Open
serpro69 opened this issue Oct 24, 2021 · 4 comments
Open

New 'date' provider #95

serpro69 opened this issue Oct 24, 2021 · 4 comments
Labels
core 🧬 Issue related to :core module enhancement 🚀 New feature or request

Comments

@serpro69
Copy link
Owner

Would probably be useful to have functions for generating different dates from within faker

@serpro69 serpro69 added enhancement 🚀 New feature or request core 🧬 Issue related to :core module labels Oct 24, 2021
@TZanke
Copy link
Contributor

TZanke commented Apr 14, 2022

is there any known way to generate a date inside faker?

person.birthDate returns a LocalDate instead of Date.

@serpro69
Copy link
Owner Author

Hi @TZanke ,

I'm not sure I completely understand the question. If you're asking about this particular issue - it hasn't been worked on yet, so there's no way to generate "plain random dates" yet. But I would still prefer to return java.time classes from the faker.date.XXX functions.

The person.birthDate function that you mention returns a "random" date for a given person's age, so it's not entirely "random date", but more related to a person's information.

Also, are you referring to java.util.Date or some other "Date" class when you say "returns a LocalDate instead of Date."? And if it is java.util.Date, can you clarify why you'd want that? The only reason I can think of for wanting java.util.Date is if you're using java version < 1.8 and don't have the java.time APIs. If this is in fact what you need - please open a separate issue for supporting older java versions.

@TZanke
Copy link
Contributor

TZanke commented Apr 26, 2022

Thank you for your reply. I am new to Kotlin / Java and was using the old time APIs till know. I wasn't aware of java.time. I now migrated the whole codebase to the new apis. Works like a charm. Thank you.

Faker provider i would love to have in future:

  • LocalDate (will use person.birthDate as a temporary workaround)
  • ZonedLocalDate

@serpro69
Copy link
Owner Author

It's possible and quite easy to convert from one java.time type to another, so I don't see much point in creating functions with all possible return types. Although I have been thinking that it could be better to return ZonedDateTime (or even Instant) instead of LocalDateTime and that's what I'll probably go for in the Date provider. But I don't think I'll do that for the person.birthDate unless someone complains about it :D

As for person.birthDate. As I mentioned, at least in my mind it has a very specific use case and should generally be used for generating personal data, along with other functions in the Person data provider.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core 🧬 Issue related to :core module enhancement 🚀 New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants