Skip to content

Commit

Permalink
fix: Fix CustomParseFormat Plugin to set correct locale
Browse files Browse the repository at this point in the history
  • Loading branch information
iamkun committed Dec 19, 2019
1 parent 6b587da commit 66ce23f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/plugin/customParseFormat/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ export default (o, C, d) => {
locale = pl ? d.Ls[pl] : this.$locale()
this.$d = parseFormattedInput(date, format, utc)
this.init(cfg)
if (pl) this.$L = pl
} else {
oldParse.call(this, cfg)
}
Expand Down
12 changes: 10 additions & 2 deletions test/plugin/customParseFormat.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,12 +192,20 @@ it('correctly parse ordinal', () => {
const inputFalse = '7st March 2019'
const inputZHCN = '7日 三月 2019'
const format = 'Do MMMM YYYY'
const displayFormatWithLocale = 'MMMM dddd'
expect(dayjs(input, format).valueOf())
.toBe(moment(input, format).valueOf())
expect(dayjs(input2, format).valueOf())
.toBe(moment(input2, format).valueOf())
expect(dayjs(inputFalse, format).valueOf())
.toBe(moment(inputFalse, format).valueOf())
expect(dayjs(inputZHCN, format, 'zh-cn').valueOf())
.toBe(moment(inputZHCN, format, 'zh-cn').valueOf())

const dayjsCN = dayjs(inputZHCN, format, 'zh-cn')
const momentCN = moment(inputZHCN, format, 'zh-cn')
expect(dayjsCN.valueOf())
.toBe(momentCN.valueOf())
expect(dayjsCN.format(displayFormatWithLocale))
.toBe(momentCN.format(displayFormatWithLocale))
expect(dayjsCN.locale())
.toBe(momentCN.locale())
})

0 comments on commit 66ce23f

Please sign in to comment.