Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Change numeric option from auto to always for format.relativeTime #765

Merged
merged 4 commits into from
Jan 9, 2024

Conversation

amannn
Copy link
Owner

@amannn amannn commented Jan 9, 2024

Fixes #757

Previously, numeric: 'auto' was used for formatting relative times. This occasionally produces incorrect output when values are rounded based on the unit, therefore it's changed to always now. The only exception are cases <1s which render as "now" via numeric: 'auto' (instead of "0 seconds ago").

Previous behavior:

// Output: "Last year"
format.relativeTime(
  new Date("2022-07-11T00:00:00.000Z"),
  new Date("2024-01-17T00:00:00.000Z")
);

New behavior:

// Output: "1 year ago"
format.relativeTime(
  new Date("2022-07-11T00:00:00.000Z"),
  new Date("2024-01-17T00:00:00.000Z")
);

Note that this is considered as "1 year" due to rounding. Once a difference of 1.5 years is reached, then "2 years ago" will be displayed.


See also these tests from the latest version of next-intl in comparison to date-fns: https://codesandbox.io/p/devbox/lm6svh?file=%2Fsrc%2FApp.tsx%3A30%2C14

Copy link

vercel bot commented Jan 9, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
next-intl-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 9, 2024 2:28pm
next-intl-example-app-router ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 9, 2024 2:28pm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

formatter.relativeTime outputs wrong relative time
1 participant