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.23k stars 2.26k forks source link

String + Format parse fails when string includes 'dddd' #1789

Open pketh opened 2 years ago

pketh commented 2 years ago

Describe the bug Using the version on the dayjs website (via the web console), I can construct dates like Tuesday Feb 1/22 with

date = dayjs(new Date())
date.format('dddd MMM D/YY')

But attempting to parse them with the same format string returns Invalid Date

dayjs('Tuesday Feb 1/22', 'dddd MMM D/YY')

Expected behavior

the parser would return a valid dayjs object

Information

pketh commented 2 years ago

The only way to get this to work right now is to manually remove the dddd from the string and just parse

dayjs('Feb 1/22', 'MMM D/YY')

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.

So perhaps this should be a feature request.