diff --git a/src/constant.js b/src/constant.js index 6be602e2..22d6e8ad 100644 --- a/src/constant.js +++ b/src/constant.js @@ -26,5 +26,5 @@ export const FORMAT_DEFAULT = 'YYYY-MM-DDTHH:mm:ssZ' export const INVALID_DATE_STRING = 'Invalid Date' // regex -export const REGEX_PARSE = /^(\d{4})[-/]?(\d{1,2})?[-/]?(\d{0,2})[^0-9]*(\d{1,2})?:?(\d{1,2})?:?(\d{1,2})?[.:]?(\d+)?$/ +export const REGEX_PARSE = /^(\d{4})[-/]?(\d{1,2})?[-/]?(\d{0,2})[Tt\s]*(\d{1,2})?:?(\d{1,2})?:?(\d{1,2})?[.:]?(\d+)?$/ export const REGEX_FORMAT = /\[([^\]]+)]|Y{1,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a|A|m{1,2}|s{1,2}|Z{1,2}|SSS/g diff --git a/test/parse.test.js b/test/parse.test.js index 1dd38207..a8dc739a 100644 --- a/test/parse.test.js +++ b/test/parse.test.js @@ -201,4 +201,12 @@ describe('REGEX_PARSE', () => { expect(dayjs(date).valueOf()).toBe(moment(date).valueOf()) expect(d).toBe(null) }) + + // dots should not be matched, and fallback to Date + it('2021.01.03', () => { + const date = '2021.01.03' + const d = date.match(REGEX_PARSE) + expect(dayjs(date).valueOf()).toBe(moment(date).valueOf()) + expect(d).toBe(null) + }) })