Skip to content

Commit b7f62b4

Browse files
authored
Merge pull request #1928 from iamkun/dev
D2M
2 parents 2400277 + eaab693 commit b7f62b4

File tree

3 files changed

+58
-3
lines changed

3 files changed

+58
-3
lines changed

src/locale/nl.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const locale = {
88
weekdaysMin: 'zo_ma_di_wo_do_vr_za'.split('_'),
99
months: 'januari_februari_maart_april_mei_juni_juli_augustus_september_oktober_november_december'.split('_'),
1010
monthsShort: 'jan_feb_mrt_apr_mei_jun_jul_aug_sep_okt_nov_dec'.split('_'),
11-
ordinal: n => `${n}.`,
11+
ordinal: n => `${n}${n === 1 || n === 8 || n >= 20 ? 'ste' : 'de'}`,
1212
weekStart: 1,
1313
yearStart: 4,
1414
formats: {

src/plugin/customParseFormat/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { u } from '../localizedFormat/utils'
22

3-
const formattingTokens = /(\[[^[]*\])|([-:/.()\s]+)|(A|a|YYYY|YY?|MM?M?M?|Do|DD?|hh?|HH?|mm?|ss?|S{1,3}|z|ZZ?)/g
3+
const formattingTokens = /(\[[^[]*\])|([-_:/.,()\s]+)|(A|a|YYYY|YY?|MM?M?M?|Do|DD?|hh?|HH?|mm?|ss?|S{1,3}|z|ZZ?)/g
44

55
const match1 = /\d/ // 0 - 9
66
const match2 = /\d\d/ // 00 - 99
@@ -9,7 +9,7 @@ const match4 = /\d{4}/ // 0000 - 9999
99
const match1to2 = /\d\d?/ // 0 - 99
1010
const matchSigned = /[+-]?\d+/ // -inf - inf
1111
const matchOffset = /[+-]\d\d:?(\d\d)?|Z/ // +00:00 -00:00 +0000 or -0000 +00 or Z
12-
const matchWord = /\d*[^\s\d-_:/()]+/ // Word
12+
const matchWord = /\d*[^-_:/,()\s\d]+/ // Word
1313

1414
let locale = {}
1515

test/plugin/customParseFormat.test.js

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,61 @@ it('custom two-digit year parse function', () => {
370370
expect(dayjs(input3, format).year()).toBe(1899)
371371
})
372372

373+
// issue 1852
374+
describe('parse with special separator characters', () => {
375+
it('Output is NaN for a specific date format', () => {
376+
const input = '20 Nov, 2022'
377+
const format = 'DD MMM, YYYY'
378+
const locale = 'en'
379+
const resultDayjs = dayjs(input, format, locale)
380+
const resultMoment = moment(input, format, locale)
381+
expect(resultMoment.isValid()).toBe(true)
382+
expect(resultDayjs.isValid()).toBe(true)
383+
expect(resultDayjs.format('DD-MM-YYYY')).toBe('20-11-2022')
384+
expect(resultMoment.format('DD-MM-YYYY')).toBe('20-11-2022')
385+
})
386+
it('parse comma separated date', () => {
387+
const input = '20,11,2022'
388+
const format = 'DD,MM,YYYY'
389+
const resultDayjs = dayjs(input, format)
390+
const resultMoment = moment(input, format)
391+
expect(resultMoment.isValid()).toBe(true)
392+
expect(resultDayjs.isValid()).toBe(true)
393+
expect(resultDayjs.format('DD-MM-YYYY')).toBe('20-11-2022')
394+
expect(resultMoment.format('DD-MM-YYYY')).toBe('20-11-2022')
395+
})
396+
it('parse comma separated date in strict mode', () => {
397+
const input = '20,11,2022'
398+
const format = 'DD,MM,YYYY'
399+
const resultDayjs = dayjs(input, format, true)
400+
const resultMoment = moment(input, format, true)
401+
expect(resultMoment.isValid()).toBe(true)
402+
expect(resultDayjs.isValid()).toBe(true)
403+
expect(resultDayjs.format('DD-MM-YYYY')).toBe('20-11-2022')
404+
expect(resultMoment.format('DD-MM-YYYY')).toBe('20-11-2022')
405+
})
406+
it('parse date with multi character separator', () => {
407+
const input = '20---11---2022'
408+
const format = 'DD-/-MM-#-YYYY'
409+
const resultDayjs = dayjs(input, format)
410+
const resultMoment = moment(input, format)
411+
expect(resultMoment.isValid()).toBe(true)
412+
expect(resultDayjs.isValid()).toBe(true)
413+
expect(resultDayjs.format('DD-MM-YYYY')).toBe('20-11-2022')
414+
expect(resultMoment.format('DD-MM-YYYY')).toBe('20-11-2022')
415+
})
416+
it('parse date with multi character separator in strict mode', () => {
417+
const input = '20-/-11-#-2022'
418+
const format = 'DD-/-MM-#-YYYY'
419+
const resultDayjs = dayjs(input, format, true)
420+
const resultMoment = moment(input, format, true)
421+
expect(resultMoment.isValid()).toBe(true)
422+
expect(resultDayjs.isValid()).toBe(true)
423+
expect(resultDayjs.format('DD-MM-YYYY')).toBe('20-11-2022')
424+
expect(resultMoment.format('DD-MM-YYYY')).toBe('20-11-2022')
425+
})
426+
})
427+
373428
it('parse X x', () => {
374429
const input = '1410715640.579'
375430
const format = 'X'

0 commit comments

Comments
 (0)