iamkun / dayjs

⏰ Day.js 2kB immutable date-time library alternative to Moment.js with the same modern API
https://day.js.org
MIT License
46.97k stars 2.3k forks source link

Loading the customParseFormat plugin causes parsing some formats to return invalid dates #1802

Open RobM-ADP opened 2 years ago

RobM-ADP commented 2 years ago

When parsing dates using the following format:

dddd, MMMM D, YYYY h:mm A

parsing works correctly until you load the customParseFormat plugin at which point parsing of the date no longer works. For example, using the following code formatting the date to the huge format and then parsing it does not work. If you remove this line: dayjs.extend(window.dayjs_plugin_customParseFormat); then it works as expected.

// if you don't load this plugin the parsing works as expected
dayjs.extend(window.dayjs_plugin_customParseFormat);

const hugeFormat = 'dddd, MMMM D, YYYY h:mm A';
// format as huge
const hugeFeb16 = dayjs('2022-02-16').format(hugeFormat);
console.log(hugeFeb16);

// parse huge formatted expecting to be valid
console.log(dayjs(hugeFeb16, hugeFormat, false).isValid());

https://jsfiddle.net/mcgraphix/2qk5t61m/7/

Expected behavior I would expect that the addition of the plugin would not break parsing of other formats

Information

BePo65 commented 2 years ago

Neither moment nor dayjs have a parsing token dddd; so parsing with a format of dddd, MMMM D, YYYY h:mm A creates an invalid date (see also issue #1789).

So perhaps this should be a feature request.