dayjs icon indicating copy to clipboard operation
dayjs copied to clipboard

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

Open github-roushan opened this issue 11 months ago • 4 comments

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:

  • 1 week, 4 days, 13 hours, 46 minutes, and 40 seconds (validated via [MilliSecond Converter].
    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 avatar Jan 16 '25 18:01 github-roushan

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

SupertigerDev avatar Mar 28 '25 08:03 SupertigerDev

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.

github-roushan avatar Mar 28 '25 13:03 github-roushan

image I see, this is how it currently is. I hope this gets merged soon 🙏

SupertigerDev avatar Mar 28 '25 13:03 SupertigerDev

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

github-roushan avatar Mar 28 '25 18:03 github-roushan