Skip to content

Conversation

@ayush-pandey047
Copy link

Fixed a bug in the relativeTime plugin where durations crossing the month or year threshold displayed incorrect units, such as showing "28 months ago" instead of "28 days ago", or "12 years ago" instead of "12 months ago".
The threshold logic has been updated to correctly determine transitions between days → months → years.

Changes Made

  • Refined threshold calculation in relativeTime to correctly identify when to switch between units.
  • Fixed logic that caused incorrect month/year display for near-threshold durations.
  • Added customRelativeTime.js for easier debugging and controlled customization.
  • Added test.mjs to verify relativeTime behavior and regression prevention.
  • Added a dedicated test to ensure English locale uses short relative strings correctly.

Verification

  • All plugin and locale tests executed using npm test.
  • Confirmed English locale short relativeTime strings behave correctly.
  • Validated with Moment.js for consistency where applicable.
  • After verifying correctness, you can also test independently using
    (node test.mjs)
    If all outputs match the expected results, both test.mjs and customRelativeTime.js can be safely removed.

console.log(old.fromNow());
console.log('Now:', now.toISOString());
console.log('Old:', old.toISOString());
console.log(dayjs.Ls.en.relativeTime);
Copy link
Contributor

Choose a reason for hiding this comment

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

do we need all these console logs?

Copy link
Author

Choose a reason for hiding this comment

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

This console helps you check the current test time. If anyone wants to make updates, they can test them here and instantly see the results.

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.

2 participants