Skip to content

Commit 058d624

Browse files
authoredApr 28, 2020
fix: Fix Duration plugin .toISOString format bug (#889)
* fix: Fix Duration Plugin `.toISOString` format bug fix #888 * test: Update RelativeTime plugin test
1 parent db642ac commit 058d624

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed
 

‎src/plugin/duration/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ class Duration {
9595
seconds += this.$d.milliseconds / 1000
9696
}
9797
const S = seconds ? `${seconds}S` : ''
98-
const T = (H || M || S) ? 'T' : ''
98+
const T = (H || m || S) ? 'T' : ''
9999
const result = `P${Y}${M}${D}${T}${H}${m}${S}`
100100
return result === 'P' ? 'P0D' : result
101101
}

‎test/plugin/duration.test.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ describe('Creating', () => {
2323
})
2424
it('two argument will bubble up to the next', () => {
2525
expect(dayjs.duration(59, 'seconds').toISOString()).toBe('PT59S')
26-
expect(dayjs.duration(60, 'seconds').toISOString()).toBe('P1M')
26+
expect(dayjs.duration(60, 'seconds').toISOString()).toBe('PT1M')
2727
expect(dayjs.duration(13213, 'seconds').toISOString()).toBe('PT3H40M13S')
2828
})
2929
it('object with float', () => {
@@ -78,7 +78,7 @@ it('Is duration', () => {
7878
it('toJSON', () => {
7979
expect(JSON.stringify({
8080
postDuration: dayjs.duration(5, 'minutes')
81-
})).toBe('{"postDuration":"P5M"}')
81+
})).toBe('{"postDuration":"PT5M"}')
8282
})
8383

8484
describe('Humanize', () => {

‎test/plugin/relativeTime.test.js

+6
Original file line numberDiff line numberDiff line change
@@ -137,3 +137,9 @@ it('Custom thresholds and rounding support', () => {
137137
})
138138
expect(dayjs().subtract(45, 'm').fromNow()).toBe('45 minutes ago')
139139
})
140+
141+
it('Locale without relativeTime config fallback', () => {
142+
expect(dayjs().locale({
143+
name: 'test-locale'
144+
}).fromNow()).toEqual(expect.any(String))
145+
})

0 commit comments

Comments
 (0)
Please sign in to comment.