Skip to content

fix(utilities/date-time-format): cap relative months at 12 - #24059

Open
kwy404 wants to merge 3 commits into
carbon-design-system:mainfrom
kwy404:fix/relative-format-month-cap
Open

kwy404 wants to merge 3 commits into
carbon-design-system:mainfrom
kwy404:fix/relative-format-month-cap

Conversation

@kwy404

@kwy404 kwy404 commented Nov 14, 2026

Copy link
Copy Markdown
Contributor

dateTimeFormat.relative.format shows "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, and Math.trunc(52 / 4) is 13.

Fix: clamp months to 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

  • Tests for a date 364 days in the past and in the future

Changed

  • relative.format never reports more than 12 months

Removed

  • Nothing

Testing / Reviewing

Run yarn test packages/utilities/src/dateTimeFormat/relative-test.js.

The new -364 days and +364 days tests fail on main for all three styles (Expected: "12 months ago", Received: "13 months ago") and pass with this change.

All 14 test suites (334 tests) in packages/utilities pass, and ESLint, Prettier and tsc --noEmit -p packages/utilities/tsconfig.json are clean.

PR Checklist

As the author of this PR, before marking ready for review, confirm you:

  • Reviewed every line of the diff
  • Updated documentation and storybook examples
  • Followed the required v12 migration documentation for any code change that affects v12, or struck through this item because the PR does not affect v12
  • Wrote passing tests that cover this change
  • Addressed any impact on accessibility (a11y)
  • Tested for cross-browser consistency
  • Validated that this code is ready for review and status checks should pass

More details can be found in the pull request guide

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>
@kwy404
kwy404 requested a review from a team as a code owner November 14, 2026 23:53
@netlify

netlify Bot commented Nov 14, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for v12-carbon-react ready!

Name Link
🔨 Latest commit 8a5ece2
🔍 Latest deploy log https://app.netlify.com/projects/v12-carbon-react/deploys/6afb2e7528e3145f7706be69
😎 Deploy Preview https://deploy-preview-24059--v12-carbon-react.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

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

@netlify

netlify Bot commented Nov 14, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for v12-carbon-web-components ready!

Name Link
🔨 Latest commit 8a5ece2
🔍 Latest deploy log https://app.netlify.com/projects/v12-carbon-web-components/deploys/6afb246730a74d5b9b244863
😎 Deploy Preview https://deploy-preview-24059--v12-carbon-web-components.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

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

@netlify

netlify Bot commented Nov 14, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for v11-carbon-react ready!

Name Link
🔨 Latest commit 8a5ece2
🔍 Latest deploy log https://app.netlify.com/projects/v11-carbon-react/deploys/6afb2467eb089d5996096647
😎 Deploy Preview https://deploy-preview-24059--v11-carbon-react.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

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

@netlify

netlify Bot commented Nov 14, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for carbon-elements ready!

Name Link
🔨 Latest commit 8a5ece2
🔍 Latest deploy log https://app.netlify.com/projects/carbon-elements/deploys/6afb2467f985d37f1658ca10
😎 Deploy Preview https://deploy-preview-24059--carbon-elements.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

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

@codecov

codecov Bot commented Nov 15, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.74%. Comparing base (fa75d78) to head (8a5ece2).
⚠️ Report is 13 commits behind head on main.

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     
Flag Coverage Δ
main-packages 88.12% <ø> (-0.11%) ⬇️
web-components 91.52% <ø> (-0.46%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 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.

@carbon-monitor-agent

Copy link
Copy Markdown
Collaborator

[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.

kennylam and others added 2 commits November 16, 2026 10:42
Co-authored-by: Adam Alston <aalston9@gmail.com>
Co-authored-by: Adam Alston <aalston9@gmail.com>
@netlify

netlify Bot commented Nov 16, 2026

Copy link
Copy Markdown

✅ Deploy Preview for v11-carbon-web-components ready!

Name Link
🔨 Latest commit 8a5ece2
🔍 Latest deploy log https://app.netlify.com/projects/v11-carbon-web-components/deploys/6afb24671c7fc411cb4a4288
😎 Deploy Preview https://deploy-preview-24059--v11-carbon-web-components.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

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

This branch was successfully deployed

1 active deployment
@carbon/react storybook preview — 8a5ece20 Deployed Nov 16, 2026 by kennylam via react-storybook-preview #45283
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants