Skip to content

Commit

Permalink
fix: update plugin advancedFormat isValid validation (#1566)
Browse files Browse the repository at this point in the history
  • Loading branch information
imwh0im committed Jul 7, 2021
1 parent eb087f5 commit 755fc8b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/plugin/advancedFormat/index.js
Expand Up @@ -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) => {
Expand Down
4 changes: 4 additions & 0 deletions test/plugin/advancedFormat.test.js
Expand Up @@ -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())
})
Expand Down

0 comments on commit 755fc8b

Please sign in to comment.