Invalid duration when using partial object parameter in the creator
- Dominant language
- JavaScript
- Stars
- 48.7k
- Forks
- 2.5k
- PR merge metrics
- No merged PRs in 30d
Description
**Describe the bug**
The Duration creator returns incomplete duration if passed the object parameter that's partial:


**Solution**
Adding `this.parseFromMilliseconds()` [in the constructor for the code branch handling the object parameter](https://github.com/iamkun/dayjs/blob/2076da970047c6e0a22c8d4243a42d52833a5df2/src/plugin/duration/index.js#L80) solves it:
```diff
if (typeof input === 'object') {
Object.keys(input).forEach((k) => {
this.$d[prettyUnit(k)] = input[k]
})
this.calMilliseconds()
+ this.parseFromMilliseconds()
return this
}
```
**Information**
- Day.js Version: 1.11.10
Contributor guide
Research direction
Start in src/plugin/duration/index.js at the object-parameter branch identified in the issue, and reproduce the incomplete result with a partial duration object. Verify that the duration's component values and millisecond total are consistent after construction; the issue's proposed behavior provides the completion check.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- api
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 52/100