Skip to content

Commit db2b6a5

Browse files
committed
fix: fix parse regex bug (#1307)
fix #1305
1 parent 873b749 commit db2b6a5

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

src/constant.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,5 @@ export const FORMAT_DEFAULT = 'YYYY-MM-DDTHH:mm:ssZ'
2626
export const INVALID_DATE_STRING = 'Invalid Date'
2727

2828
// regex
29-
export const REGEX_PARSE = /^(\d{4})[-/]?(\d{1,2})?[-/]?(\d{0,2})[^0-9]*(\d{1,2})?:?(\d{1,2})?:?(\d{1,2})?\.?(\d+)?$/
29+
export const REGEX_PARSE = /^(\d{4})[-/]?(\d{1,2})?[-/]?(\d{0,2})[^0-9]*(\d{1,2})?:?(\d{1,2})?:?(\d{1,2})?[.:]?(\d+)?$/
3030
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

test/parse.test.js

+8
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,14 @@ describe('REGEX_PARSE', () => {
174174
expect(d).toBe(null)
175175
})
176176

177+
// format used in timezone plugin utcString
178+
it('2021-1-4 0:42:53:000', () => {
179+
const date = '2021-1-4 0:42:53:000'
180+
const d = date.match(REGEX_PARSE)
181+
expect(dayjs(date).valueOf()).toBe(moment(date).valueOf())
182+
expect(d.join('-')).toBe('2021-1-4 0:42:53:000-2021-1-4-0-42-53-000')
183+
})
184+
177185
it('2020-12-31T18:00:00-05:00 (no regex match)', () => {
178186
const date = '2020-12-31T18:00:00-05:00'
179187
const d = date.match(REGEX_PARSE)

0 commit comments

Comments
 (0)