question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[new feature] Allow chance.birthday({minAge, maxAge})

See original GitHub issue

I 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:

  1. day range follows the rule currently used into Chance.prototype.birthday:
min.setFullYear(currentYear - age - 1);
max.setFullYear(currentYear - age);
  1. 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:open
  • Created a year ago
  • Comments:9 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
victorquinncommented, Sep 9, 2022

No issue on my end, it looks like you closed it yourself, maybe an accident?

Screen Shot 2022-09-09 at 2 12 37 PM

1reaction
victorquinncommented, Sep 8, 2022

Love it, would gladly accept a PR with this!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found