-
Notifications
You must be signed in to change notification settings - Fork 339
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
Person date of birth #1470
Comments
We have a separate provider for the date/time related data: Datetime. |
I realize that, but unless I'm overlooking something, nothing that quite does the same thing. I mentioned that there are ways around this using the Datetime or other random numbers. |
This is a function I came up with. def date_of_birth(minimum_age: int = 21, maximum_age: int = 115):
current_year = datetime.now().year
return gen.datetime.date(
start=current_year - maximum_age, end=current_year - minimum_age
) Which could easily be converted to a method of def date_of_birth(self, minimum_age: int = 21, maximum_age: int = 115):
return self.date(start=self._CURRENT_YEAR - maximum_age, end=self._CURRENT_YEAR - minimum_age) When I get a little time I plan to submit a PR. |
I agree. I'll add this method. |
Version 13.1.0 has been published and is available for download. Thanks everyone. See https://github.com/lk-geimfari/mimesis/releases/tag/v13.1.0 for more details. I'm closing this issue. |
Feature request
I would love it if the Person provider had a function to quickly create a date of birth for a given age range, which imho is a common requirement when creating fake person data. I see that you can work around that with creating random dates and setting fitting start/end dates, but as a quality of life addition, I think a Person.date_of_birth() function would be very useful.
See for comparison the way Faker does birthdays: https://faker.readthedocs.io/en/master/locales/de_DE.html?highlight=date_of_birth#faker.providers.date_time.de_DE.Provider.date_of_birth
Thesis
What I propose is that in addition to just age(), you should be able to generate a plausible date of birth for a given person. It should have some sensible defaults, so that for example it doesn't generate 200 year old people or babies, which are unlikely to be users of your application. I think the API that Faker provides is pretty intuitive, so I'm going to use it in these examples.
Reasoning
In a typical application, you usually do not store the user's (or any person's) age as a number. It's far more common to store a date of birth and derive the age from that when you need it. I could use completely random datetimes, but sometimes it's necessary to check certain cases like "is the user 13/18/21 or above", where you need a certain age for the test, but still have it result in a datetime.
You can work around this by doing something like
but that is not as clean or intuitive as it could be. In my mind, frameworks like this are all about quality of life and plausible data, because otherwise we may as well use raw random numbers and strings everywhere, so in that sense, it would be a useful addition.
If you agree that this is useful, I can work on a pull request for it. If somehow I missed an obvious way to do this already, please point me in the right direction.
The text was updated successfully, but these errors were encountered: