iamkun / iamkun/dayjs

Different output dates when using the non strict parsing mode

Open
#1,368 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**
When creating a new date using the **non strict parsing mode** and including the **customParseFormat** plugin, I get the following results:
```
dayjs('201911', 'YYYY-M', false); // Jan 1st 2019
dayjs('201911', 'YYYYM', false); // Nov 1st 2019
dayjs('2019-11', 'YYYY-M', false); // Nov 1st 2019
dayjs('2019-11', 'YYYYM', false); // Nov 1st 2019
```
The first case returns Jan 1st 2019 instead of Nov 1st 2019
When removing the **customParseFormat** plugin, the output is correct: **Nov 1st 2019**

**Expected behavior**
All of these cases return **Nov 1st 2019**, according to the list of formats provided (https://day.js.org/docs/en/parse/string-format). The expected result should be the following when using the customParseFormat plugin:
```
dayjs('201911', 'YYYY-M', false); // Nov 1st 2019
dayjs('201911', 'YYYYM', false); // Nov 1st 2019
dayjs('2019-11', 'YYYY-M', false); // Nov 1st 2019
dayjs('2019-11', 'YYYYM', false); // Nov 1st 2019
```

**Information**
- Day.js Version: 1.10.4
- OS: Windows 10

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the four parsing examples with Day.js 1.10.4 and the customParseFormat plugin, then inspect that plugin's parsing path for non-strict formats. Done means all four examples return November 1st, 2019, including the unseparated YYYY-M input.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.