From bb81796b7c85b81c82c60b035517f9c5449f68ea Mon Sep 17 00:00:00 2001 From: iamkun Date: Tue, 28 Apr 2020 18:12:55 +0800 Subject: [PATCH] fix: Fix Duration Plugin `.toISOString` format bug fix #888 --- src/plugin/duration/index.js | 2 +- test/plugin/duration.test.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/plugin/duration/index.js b/src/plugin/duration/index.js index 9d3361f4e..28031b127 100644 --- a/src/plugin/duration/index.js +++ b/src/plugin/duration/index.js @@ -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 } diff --git a/test/plugin/duration.test.js b/test/plugin/duration.test.js index 350053a90..e854d9148 100644 --- a/test/plugin/duration.test.js +++ b/test/plugin/duration.test.js @@ -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', () => { @@ -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', () => {