iamkun / iamkun/dayjs

Parsing issue with timezone since 1.10.2

Open
#1,318 7 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
48.7k
Forks
2.5k
PR merge metrics
No merged PRs in 30d

Description

**Describe the bug**
Running v1.9.8:
```js
console.log(dayjs('20170719T112552+0000'))

/*
d {
'$L': 'en',
'$d': 2017-07-19T09:25:52.000Z,
'$x': {},
'$y': 2017,
'$M': 6,
'$D': 19,
'$W': 3,
'$H': 11,
'$m': 25,
'$s': 52,
'$ms': 0
}
*/
```

Running v1.10.2:
```js
console.log(dayjs('20170719T112552+0000'))

/*
d {
'$L': 'en',
'$d': Invalid Date,
'$x': {},
'$y': NaN,
'$M': NaN,
'$D': NaN,
'$W': NaN,
'$H': NaN,
'$m': NaN,
'$s': NaN,
'$ms': NaN
}
*/
```

Removing the timezone from the source string and the date is parsed again:
```js
console.log(dayjs('20170719T112552'))

/*
d {
'$L': 'en',
'$d': 2017-07-19T09:25:52.000Z,
'$x': {},
'$y': 2017,
'$M': 6,
'$D': 19,
'$W': 3,
'$H': 11,
'$m': 25,
'$s': 52,
'$ms': 0
}
*/
```

Looks like the regex (https://github.com/iamkun/dayjs/pull/1307) still need improvement I guess?

**Expected behavior**
Date properly parsed.

**Information**
- Day.js Version: 1.10.2
- OS: macOS
- Browser: node 12
- Time zone: [e.g. GMT-07:00 DST (Pacific Daylight Time)]

Contributor guide

Open the contributing guide

Research direction

Review the regex change referenced in pull request #1307 and trace the parsing path exercised by dayjs('20170719T112552+0000'). Reproduce the regression against the timezone-bearing and timezone-free strings, then verify that the timezone-bearing form produces a valid date without breaking the existing form.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.