Repository navigation
fix(date): keep past and future within the year range when refDate is a leap day - #4215
Conversation
✅ Deploy Preview for fakerjs ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify project configuration. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## next #4215 +/- ##
=======================================
Coverage 99.18% 99.18%
=======================================
Files 1179 1180 +1
Lines 3947 3947
Branches 713 713
=======================================
Hits 3915 3915
Misses 28 28
Partials 4 4
🚀 New features to boost your workflow:
|
ST-DDT
left a comment
There was a problem hiding this comment.
I'm not sure about the lower bounds each, as it now is technically one day before the refDate.
…-day refDate The earliest past() date must stay within years.max years and the earliest future() date at least years.min years away, so those bounds keep the March 1 rollover; only the latest bounds clamp to February 28.
|
Good point, thanks. With |
|
Thanks for the suggestions, applied all four in f6b12ab: both test comments now use the "would be less/more than" wording, and in |
Follow-up to #4208, as discussed there:
pastandfutureshould handle a leap-dayrefDatethe same waybirthdatedoes.faker.date.past()andfaker.date.future()build their bounds by movingrefDateby whole years withsetUTCFullYear. WhenrefDateis February 29 and the target year is a common year, the bound rolls over to March 1:This moves
sameDayInYear(added forbirthdatein #4208, which clamps February 29 to February 28 in a common year, like date-fnsaddYears/subYears) tosrc/modules/date/_utils.tsand uses it for both bounds inpastandfuture. Other dates are unchanged.Tests: four fixed-randomizer tests (like the existing
past/futurerange tests) pin each end of the range for a 2024-02-29refDate; all four fail onnextand pass with the fix.test/modules/date.spec.tsandtest/internalpass locally (775 tests), and no snapshots change.AI-assisted: I directed the investigation and reviewed and verified the change myself.