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

Make Faker.Date.date_of_birth/1 with valid dates #100

Closed
igas opened this issue Jul 17, 2017 · 3 comments
Closed

Make Faker.Date.date_of_birth/1 with valid dates #100

igas opened this issue Jul 17, 2017 · 3 comments

Comments

@igas
Copy link
Member

igas commented Jul 17, 2017

Right now dob can't be on 30 or 31. Suggestion is to introduce private function to_valid_day(date, month, year) and return maximum possible date, for example:

to_valid_day(31, 9, 2017) # => 30

In case of February we'll need to check for leap year.

@tobyhinloopen
Copy link
Contributor

tobyhinloopen commented Jul 18, 2017

Isn't there some kind of common library that can represent a range of dates (EG a range from 17 years ago to 18 years ago) so we can just Enum.random it?

@lauraannwilliams
Copy link
Contributor

lauraannwilliams commented Jul 28, 2017

@tobyhinloopen
Copy link
Contributor

tobyhinloopen commented Nov 11, 2017

Fixed by MR #116

Enum.map(0..1000, fn i -> Faker.Date.date_of_birth(1).day end) 
|> Enum.reduce(%{}, fn day, acc -> Map.update(acc, day, 0, &(&1 + 1)) end)
%{1 => 40, 2 => 27, 3 => 35, 4 => 39, 5 => 25, 6 => 32, 7 => 21, 8 => 18,
  9 => 37, 10 => 28, 11 => 24, 12 => 28, 13 => 27, 14 => 30, 15 => 43, 16 => 26,
  17 => 31, 18 => 29, 19 => 36, 20 => 31, 21 => 31, 22 => 38, 23 => 21,
  24 => 41, 25 => 42, 26 => 32, 27 => 39, 28 => 36, 29 => 44, 30 => 29,
  31 => 10}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants