Skip to content

feat(date): add ability to provide year range for past and future#3783

Merged
ST-DDT merged 3 commits intonextfrom
feat/3653-numeric-range-date-fns
Apr 8, 2026
Merged

feat(date): add ability to provide year range for past and future#3783
ST-DDT merged 3 commits intonextfrom
feat/3653-numeric-range-date-fns

Conversation

@xDivisionByZerox
Copy link
Copy Markdown
Member

Description

This PR fixes #3653.

Changes

  • Add a small helper function to convert a number of years to is ms representation. This is mostly done for readability purposes.
  • Extend the years argument in date.past() and date.future() to be able to provide a range
    • For the naming and JSDoc approach I took inspiration from the string module
    • year.max must be greater than years.min - this will be enforced by date.between() (the underlying implementation) as well, but I added an additional check to give a nicer error message
  • Added throw tags to the JSDocs of the functions - these where previously missing even tho the functions were able to throw
  • Added tests for the new behavior
    • Aligned the exist test of date.future with the one from date.past since they were more strict

Note

I quite enjoyed implementing an actual feature again. I would go ahead and implement the same feature for date.recent and date.soon in a separate PR if the team allows it.

Links

@xDivisionByZerox xDivisionByZerox added this to the v10.x milestone Mar 31, 2026
@xDivisionByZerox xDivisionByZerox requested a review from a team March 31, 2026 21:07
@xDivisionByZerox xDivisionByZerox self-assigned this Mar 31, 2026
@xDivisionByZerox xDivisionByZerox requested a review from a team as a code owner March 31, 2026 21:07
@xDivisionByZerox xDivisionByZerox added c: feature Request for new feature p: 1-normal Nothing urgent m: date Something is referring to the date module labels Mar 31, 2026
@netlify
Copy link
Copy Markdown

netlify Bot commented Mar 31, 2026

Deploy Preview for fakerjs ready!

Name Link
🔨 Latest commit c4772bf
🔍 Latest deploy log https://app.netlify.com/projects/fakerjs/deploys/69d663876b9fde0008d0394c
😎 Deploy Preview https://deploy-preview-3783.fakerjs.dev
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 31, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.89%. Comparing base (f4a1c3e) to head (c4772bf).
⚠️ Report is 1 commits behind head on next.

Additional details and impacted files
@@           Coverage Diff           @@
##             next    #3783   +/-   ##
=======================================
  Coverage   98.89%   98.89%           
=======================================
  Files         888      888           
  Lines        3065     3077   +12     
  Branches      556      546   -10     
=======================================
+ Hits         3031     3043   +12     
  Misses         30       30           
  Partials        4        4           
Files with missing lines Coverage Δ
src/modules/date/index.ts 100.00% <100.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Comment thread src/modules/date/index.ts
Comment thread src/modules/date/index.ts Outdated
Comment thread test/modules/__snapshots__/date.spec.ts.snap
Copy link
Copy Markdown
Member

@ST-DDT ST-DDT left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should apply the adjustments to recent and soon as well.

Comment thread src/modules/date/index.ts
@xDivisionByZerox
Copy link
Copy Markdown
Member Author

We should apply the adjustments to recent and soon as well.

As I said in the PR description, I would suggest providing an additional PR for this. Alternatively, the PR title could be extended even further.
All I want is that the concrete functions are named in the autogenerated changelog when releasing.

Comment thread src/modules/date/index.ts
@ST-DDT
Copy link
Copy Markdown
Member

ST-DDT commented Mar 31, 2026

As I said in the PR description, I would suggest providing an additional PR for this. Alternatively, the PR title could be extended even further.

Sorry, have missed that part of the description. Separate PR would be more clear.

@ST-DDT ST-DDT enabled auto-merge April 8, 2026 14:12
@ST-DDT ST-DDT added this pull request to the merge queue Apr 8, 2026
Merged via the queue into next with commit 237e7dc Apr 8, 2026
23 checks passed
@ST-DDT ST-DDT deleted the feat/3653-numeric-range-date-fns branch April 8, 2026 14:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c: feature Request for new feature m: date Something is referring to the date module p: 1-normal Nothing urgent

Projects

None yet

Development

Successfully merging this pull request may close these issues.

past/future date functions to support min years

3 participants