@@ -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+
373428it ( 'parse X x' , ( ) => {
374429 const input = '1410715640.579'
375430 const format = 'X'
0 commit comments