Skip to content

Commit

Permalink
Fix add(Duration) bug. iamkun#2425
Browse files Browse the repository at this point in the history
  • Loading branch information
mlkt committed Aug 24, 2023
1 parent a9d7d03 commit 0686185
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions src/plugin/duration/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,14 +258,17 @@ class Duration {
asYears() { return this.as('years') }
}

const manipulateDuration = (date, duration, k) =>
date.add(duration.years() * k, 'y')
.add(duration.months() * k, 'M')
.add(duration.days() * k, 'd')
.add(duration.hours() * k, 'h')
.add(duration.minutes() * k, 'm')
.add(duration.seconds() * k, 's')
.add(duration.milliseconds() * k, 'ms')
const manipulateDuration = (date, duration, k) => {
const add = (value, unit) => value && (date = date.add(value * k, unit))
add(duration.years(), 'y')
add(duration.months(), 'M')
add(duration.days(), 'd')
add(duration.hours(), 'h')
add(duration.minutes(), 'm')
add(duration.seconds(), 's')
add(duration.milliseconds(), 'ms')
return date
}

export default (option, Dayjs, dayjs) => {
$d = dayjs
Expand Down

0 comments on commit 0686185

Please sign in to comment.