iamkun / iamkun/dayjs

Dayjs returns Invalid Date

Open
#1,642 0 comments 7 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**
Dayjs returns Invalid Date if the date entered by a user starts with day name.

**Example code:**

```
import * as dayjs from 'dayjs';
import 'dayjs/locale/fr';

var customParseFormat = require('dayjs/plugin/customParseFormat')
dayjs.extend(customParseFormat);
var localizedFormat = require('dayjs/plugin/localizedFormat')
dayjs.extend(localizedFormat)
var day = dayjs;
day.locale('fr'); //Using french locale

text = 'vendredi 1 janvier 2021 11:40:39 heure' ;
format = 'dddd D MMMM YYYY h:mm:ss A';
day(text, format, 'fr');
```

**Executing the above line(day(text, format, 'fr')) is throwing the below error. It works only if the day name is given after YYYY. Example: '1 janvier 2021, vendredi 11:40:39 heure'.**

**ERROR:** M {$L: 'fr', $u: undefined, $d: Invalid Date, $y: NaN, $M: NaN, …}

![Screen Shot 2021-09-22 at 1 13 58 PM](https://user-images.githubusercontent.com/28709895/134390568-58cc1388-e793-489a-ae73-eca136247fc2.png)

**Expected behavior**
Dayjs should return correct Date if the date entered by a user starts with day name.

**Information**
- Day.js Version - 1.10.7
- OS - macOS Big Sur
- Browser - Chrome 93.0.4577.82

Contributor guide

Open the contributing guide

Research direction

Start at the customParseFormat plugin entry point and reproduce the supplied French date example with the day name at the beginning. Trace how the dddd token is parsed before the date components, then verify that the example returns a valid Date while preserving the existing ordering behavior.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.