Skip to content

Commit

Permalink
fix: update customParseFormat plugin strict x X parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
iamkun committed Jul 7, 2021
1 parent 755fc8b commit 3aa2e91
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/plugin/customParseFormat/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,10 @@ export default (o, C, d) => {
this.$d = parseFormattedInput(date, format, utc)
this.init()
if (pl && pl !== true) this.$L = this.locale(pl).$L
if (isStrict && date !== this.format(format)) {
// use != to treat
// input number 1410715640579 and format string '1410715640579' equal
// eslint-disable-next-line eqeqeq
if (isStrict && date != this.format(format)) {
this.$d = new Date('')
}
// reset global locale to make parallel unit test
Expand Down
5 changes: 5 additions & 0 deletions test/plugin/customParseFormat.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import '../../src/locale/ru'
import uk from '../../src/locale/uk'
import '../../src/locale/zh-cn'
import customParseFormat from '../../src/plugin/customParseFormat'
import advancedFormat from '../../src/plugin/advancedFormat'
import localizedFormats from '../../src/plugin/localizedFormat'

dayjs.extend(customParseFormat)
Expand Down Expand Up @@ -376,4 +377,8 @@ it('parse X x', () => {
const input2 = '1410715640579'
const format2 = 'x'
expect(dayjs(input2, format2).valueOf()).toBe(moment(input2, format2).valueOf())

// x X starct parse requires advancedFormat plugin
dayjs.extend(advancedFormat)
expect(dayjs(input2, format2, true).valueOf()).toBe(moment(input2, format2, true).valueOf())
})

0 comments on commit 3aa2e91

Please sign in to comment.