Repository navigation
Conversation
relative.format derives months as weeks / 4, so a month is 28 days. The months branch is used up to 364 days, which is 52 weeks, giving 13 months. A date 364 days ago was shown as "13 months ago" and one day later as "1 year ago". Clamp months to the range -12 to 12. Only dates 364 days away change. Signed-off-by: kwy404 <thekaway404@gmail.com>
✅ Deploy Preview for v12-carbon-react ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
✅ Deploy Preview for v12-carbon-web-components ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
✅ Deploy Preview for v11-carbon-react ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
✅ Deploy Preview for carbon-elements ready!
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 @@
## main #24059 +/- ##
==========================================
- Coverage 91.24% 90.74% -0.50%
==========================================
Files 905 817 -88
Lines 81020 79816 -1204
Branches 10697 10488 -209
==========================================
- Hits 73926 72433 -1493
- Misses 6902 7178 +276
- Partials 192 205 +13
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
[AI agent review — Carbon grounded] · Looks Good · Reviewed by: IBM Bob · Commit: 7ebcc7a This PR caps the month count in dateTimeFormat relative.format at 12, so dates 364 days away no longer read as 13 months. It adds past and future 364-day tests. |
Co-authored-by: Adam Alston <aalston9@gmail.com>
Co-authored-by: Adam Alston <aalston9@gmail.com>
✅ Deploy Preview for v11-carbon-web-components ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
dateTimeFormat.relative.formatshows "13 months ago" for a date 364 days ago (and "in 13 months" for 364 days ahead). One day later it switches to "1 year ago", so the output goes 12 months, 13 months, 1 year.Root cause: months are derived from weeks as
weeks / 4, so a month is 28 days. The months branch is used up to 364 days, which is 52 weeks, andMath.trunc(52 / 4)is 13.Fix: clamp
monthsto the range -12 to 12. Only dates from 364 days up to just under 365 days change (13 becomes 12), in both directions. The 4 week month is unchanged, so 28 days is still "1 month" and 336 days is still "12 months", as in the existing tests.#22616 proposed the same clamp and was closed by its author without being merged.
Changelog
New
Changed
relative.formatnever reports more than 12 monthsRemoved
Testing / Reviewing
Run
yarn test packages/utilities/src/dateTimeFormat/relative-test.js.The new
-364 daysand+364 daystests fail onmainfor all three styles (Expected: "12 months ago",Received: "13 months ago") and pass with this change.All 14 test suites (334 tests) in
packages/utilitiespass, and ESLint, Prettier andtsc --noEmit -p packages/utilities/tsconfig.jsonare clean.PR Checklist
As the author of this PR, before marking ready for review, confirm you:
Updated documentation and storybook examplesFollowed the required v12 migration documentation for any code change that affects v12, or struck through this item because the PR does not affect v12Addressed any impact on accessibility (a11y)Tested for cross-browser consistencyMore details can be found in the pull request guide