Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix customParseFormat plugin strict mode parse meridiem bug #1321

Merged
merged 1 commit into from
Jan 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/plugin/customParseFormat/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const matchSigned = /[+-]?\d+/ // -inf - inf
const matchOffset = /[+-]\d\d:?(\d\d)?/ // +00:00 -00:00 +0000 or -0000 +00
const matchWord = /\d*[^\s\d-:/()]+/ // Word

let locale
let locale = {}

function offsetFromString(string) {
if (!string) return 0
Expand Down Expand Up @@ -216,8 +216,9 @@ export default (o, C, d) => {
const isStrict = isStrictWithoutLocale || isStrictWithLocale
let pl = args[2]
if (isStrictWithLocale) [,, pl] = args
if (!isStrictWithoutLocale) {
locale = pl ? d.Ls[pl] : this.$locale()
locale = this.$locale()
if (!isStrictWithoutLocale && pl) {
locale = d.Ls[pl]
}
this.$d = parseFormattedInput(date, format, utc)
this.init()
Expand All @@ -226,7 +227,7 @@ export default (o, C, d) => {
this.$d = new Date('')
}
// reset global locale to make parallel unit test
locale = undefined
locale = {}
} else if (format instanceof Array) {
const len = format.length
for (let i = 1; i <= len; i += 1) {
Expand Down
2 changes: 2 additions & 0 deletions test/plugin/customParseFormat.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,8 @@ describe('Strict mode', () => {
const format = 'YYYY-MM-DD'
expect(dayjs(input, format).isValid()).toBe(true)
expect(dayjs(input, format, true).isValid()).toBe(false)
expect(dayjs('2020-Jan-01', 'YYYY-MMM-DD', true).isValid()).toBe(true)
expect(dayjs('30/1/2020 10:59 PM', 'D/M/YYYY h:mm A', true).isValid()).toBe(true)
})
it('with locale', () => {
const input = '2018 三月 99'
Expand Down