From 755fc8bb1c532eb991459f180eee81367d12016c Mon Sep 17 00:00:00 2001 From: henry <48340699+imwh0im@users.noreply.github.com> Date: Wed, 7 Jul 2021 11:28:47 +0900 Subject: [PATCH] fix: update plugin advancedFormat `isValid` validation (#1566) --- src/plugin/advancedFormat/index.js | 5 +++++ test/plugin/advancedFormat.test.js | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/src/plugin/advancedFormat/index.js b/src/plugin/advancedFormat/index.js index 6ebd3f43b..a78296f7a 100644 --- a/src/plugin/advancedFormat/index.js +++ b/src/plugin/advancedFormat/index.js @@ -11,6 +11,11 @@ export default (o, c, d) => { // locale needed later // extend en locale here proto.format = function (formatStr) { const locale = this.$locale() + + if (!this.isValid()) { + return oldFormat.bind(this)(formatStr) + } + const utils = this.$utils() const str = formatStr || FORMAT_DEFAULT const result = str.replace(/\[([^\]]+)]|Q|wo|ww|w|WW|W|zzz|z|gggg|GGGG|Do|X|x|k{1,2}|S/g, (match) => { diff --git a/test/plugin/advancedFormat.test.js b/test/plugin/advancedFormat.test.js index d9512e086..955f94032 100644 --- a/test/plugin/advancedFormat.test.js +++ b/test/plugin/advancedFormat.test.js @@ -24,6 +24,10 @@ afterEach(() => { MockDate.reset() }) +it('Format of invalid date', () => { + expect(dayjs(null).format('z').toLowerCase()).toEqual(moment(null).format('z').toLowerCase()) +}) + it('Format empty string', () => { expect(dayjs().format()).toBe(moment().format()) })