Invalid date while parsing `YYYYMMMDD` or `DDMMMYYYY`
Describe the bug
All the following inputs give Invalid Date as output:
dayjs("2023NOV01")dayjs("01NOV2023")dayjs("01NOV2023", "DDMMMYYYY")dayjs("2023NOV2023", "YYYYMMMDD")
Works as expected on Chrome and Node Works as expected for:
dayjs("2023-NOV-01")dayjs("01-NOV-2023")dayjs("01-NOV-2023", "DD-MMM-YYYY")dayjs("2023-NOV-2023", "YYYY-MMM-DD")
Expected behavior Expected to return a valid dayjs object.
Information
- Day.js Version 1.11.9 and 1.10.7
- OS: OSX
- Browser Firefox and Safari
- Time zone: EDT (East Daylight Time)
Temporary workaround:
const dayjsDate = dayjs(
dateString
.replace(/[0-9][A-z]/, (a) => `${a[0]}-${a[1]}`)
.replace(/[A-z][0-9]/, (a) => `${a[0]}-${a[1]}`),
);
@lbtoma i had same issue, use this plugin to fix it: https://day.js.org/docs/en/plugin/custom-parse-format
Yeah, even using the plugin the problem persists on my end 😢
At first I thought: MMM outputs a capitalized string (Nov) so it expects the same input.
However these tests show, that the output is not very predictable and adding customParseFormat creates more invalid dates:
https://codepen.io/a-sholz/pen/XWyBMBr?editors=0010
| func | with customParseFormat | without customParseFormat |
|---|---|---|
| dayjs('2023NOV01') | works | works |
| dayjs('01NOV2023') | works | works |
| dayjs('01Nov2023', 'DDMMMYYYY') | works | works |
| dayjs('01-Nov-2023', 'DD-MMM-YYYY') | works | works |
| dayjs('01NOV2023', 'DDMMMYYYY') | invalid date | works |
| dayjs('01-NOV-2023', 'DD-MMM-YYYY') | invalid date | works |
| dayjs('2023-NOV-01') | works | works |
| dayjs('01-NOV-2023') | works | works |
| dayjs('01-NOV-2023', 'DD-MMM-YYYY') | invalid date | works |
| dayjs('2023-NOV-01', 'YYYY-MMM-DD') | invalid date | works |
Edit: This is only true for Chrome. It's a different story in Safari and Firefox
I am seeing a similar issue: https://jsfiddle.net/ygtuoLpn/12/
My format is 'DDMMMYY HH:mm' for '02JAN24 20:15'