[new feature] Allow chance.birthday({minAge, maxAge})
See original GitHub issueI need to generate birthday dates within a range of ages. This is not rocket science, but the code to calculate the correct upper and lower date limits is error-prone:
- day range follows the rule currently used into
Chance.prototype.birthday
:
min.setFullYear(currentYear - age - 1);
max.setFullYear(currentYear - age);
- but the time range needs some fixes to consider days as whole – as nobody “ceases” to be the birthday person at 7:32, for example – making the full range actually greater than the given range, in years:
// this is just pseudo-code, due to `setFulTime`
min.setFulTime('00:00:00.000');
max.setDate(dt.getDate() + 1)
max.setFulTime('00:00:00.000');
max.setMilliseconds(max.getMilliseconds() -1);
Besides, that, I think the semantics of this would be very intuitive and easy to read.
Issue Analytics
- State:
- Created a year ago
- Comments:9 (9 by maintainers)
Top Results From Across the Web
Issues · chancejs/chancejs - GitHub
Chance - Random generator helper for JavaScript. Contribute to chancejs/chancejs development by ... [new feature] Allow chance.birthday({minAge, maxAge}).
Read more >Data Generation Functions and Parameters - TechDocs
Determines a date of birth, given a random age between a minimum and a maximum, on a specified date. Parameters. : MINAGE —...
Read more >Create SQL Randomized Date of Birth - DBA Stack Exchange
This will add a random number of days to 1st of January, 1900: SELECT DATEADD(DAY, CONVERT(int, CRYPT_GEN_RANDOM(2)), '1900-01-01T00:00:00');.
Read more >C# Properties - Set question - Stack Overflow
"Age" constantly changes, "Birthday" never changes. Store the person's date of birth and then you can easily calculate their age when you need ......
Read more >fng-api - PyPI
It has all of the features and customizability as the website does. ... Minage is also not allowed to be greater than maxage....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
No issue on my end, it looks like you closed it yourself, maybe an accident?
Love it, would gladly accept a PR with this!