Skip to content

Commit

Permalink
fix: fix parse regex bug (#1307)
Browse files Browse the repository at this point in the history
fix #1305
  • Loading branch information
iamkun authored Jan 4, 2021
1 parent bfaabe4 commit 9ef1714
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/constant.js
Original file line number Diff line number Diff line change
Expand Up @@ -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})[^0-9]*(\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
8 changes: 8 additions & 0 deletions test/parse.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,14 @@ describe('REGEX_PARSE', () => {
expect(d).toBe(null)
})

// format used in timezone plugin utcString
it('2021-1-4 0:42:53:000', () => {
const date = '2021-1-4 0:42:53:000'
const d = date.match(REGEX_PARSE)
expect(dayjs(date).valueOf()).toBe(moment(date).valueOf())
expect(d.join('-')).toBe('2021-1-4 0:42:53:000-2021-1-4-0-42-53-000')
})

it('2020-12-31T18:00:00-05:00 (no regex match)', () => {
const date = '2020-12-31T18:00:00-05:00'
const d = date.match(REGEX_PARSE)
Expand Down

0 comments on commit 9ef1714

Please sign in to comment.