Skip to content

Commit

Permalink
fix: Fix Duration Plugin .toISOString format bug
Browse files Browse the repository at this point in the history
fix #888
  • Loading branch information
iamkun committed Apr 28, 2020
1 parent db642ac commit bb81796
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/plugin/duration/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class Duration {
seconds += this.$d.milliseconds / 1000
}
const S = seconds ? `${seconds}S` : ''
const T = (H || M || S) ? 'T' : ''
const T = (H || m || S) ? 'T' : ''
const result = `P${Y}${M}${D}${T}${H}${m}${S}`
return result === 'P' ? 'P0D' : result
}
Expand Down
4 changes: 2 additions & 2 deletions test/plugin/duration.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ describe('Creating', () => {
})
it('two argument will bubble up to the next', () => {
expect(dayjs.duration(59, 'seconds').toISOString()).toBe('PT59S')
expect(dayjs.duration(60, 'seconds').toISOString()).toBe('P1M')
expect(dayjs.duration(60, 'seconds').toISOString()).toBe('PT1M')
expect(dayjs.duration(13213, 'seconds').toISOString()).toBe('PT3H40M13S')
})
it('object with float', () => {
Expand Down Expand Up @@ -78,7 +78,7 @@ it('Is duration', () => {
it('toJSON', () => {
expect(JSON.stringify({
postDuration: dayjs.duration(5, 'minutes')
})).toBe('{"postDuration":"P5M"}')
})).toBe('{"postDuration":"PT5M"}')
})

describe('Humanize', () => {
Expand Down

0 comments on commit bb81796

Please sign in to comment.