Fixes Issue #2750 : Inconsistent Behavior with duration.weeks()
This commit fixes the open issue #2750
Problem
The inconsistency occurs due to the following reasons:
- The
weeksproperty behaves likeasWeeks()for all units except milliseconds or weeks. - The
addfunctionality forduration.weeks()was missing.
Fix
- Updated the logic to ensure
weeksbehaves consistently across all units. - Implemented the missing
addfunctionality forduration.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 weekto a duration now works as expected.
Let me know if further adjustments are needed!
so, when the month goes up, currently the weeks doesnt go to 0. does this plan to fix that? 🙏
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.
I see, this is how it currently is. I hope this gets merged soon 🙏
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