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

Fixes Issue #2750 : Inconsistent Behavior with duration.weeks() #2811

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from

Conversation

github-roushan
Copy link

This commit fixes the open issue #2750

Problem

The inconsistency occurs due to the following reasons:

  1. The weeks property behaves like asWeeks() for all units except milliseconds or weeks.
  2. The add functionality for duration.weeks() was missing.

Fix

  • Updated the logic to ensure weeks behaves consistently across all units.
  • Implemented the missing add functionality for duration.weeks().
  • Modified and expanded test cases to reflect these changes.

Verification

For example, 1000000000 milliseconds equals:


This matches the output of the following code:
dayjs.extend(duration);
const tmpDur = dayjs.duration(1000000000);
console.log(tmpDur);

Result:

l {
  '$d': {
    years: 0,
    months: 0,
    days: 11,
    hours: 13,
    minutes: 46,
    seconds: 40,
    milliseconds: 0
  },
  '$l': 'en',
  '$ms': 1000000000
}

Modified Test Case

  • Demonstrates that adding 1 week to a duration now works as expected.

Let me know if further adjustments are needed!

@github-roushan github-roushan force-pushed the dev branch 2 times, most recently from 6c9047e to c1d37ff Compare January 17, 2025 14:09
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.

1 participant