Skip to content

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
@SupertigerDev
Copy link

SupertigerDev commented Mar 28, 2025

so, when the month goes up, currently the weeks doesnt go to 0. does this plan to fix that? πŸ™

@github-roushan
Copy link
Author

yes.
you want to give your time in denominations
as many years you can say, then month, then weeks and so on

think of it as showing value in currecny denominations.

@SupertigerDev
Copy link

image
I see, this is how it currently is. I hope this gets merged soon πŸ™

@github-roushan
Copy link
Author

Hope my code fixes it. You can also git pull the commit as submodule if you want. Let me know if there are any issues

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