Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Output is NaN for a specific date format #1852

Open
nikhil-kumar-160 opened this issue Apr 11, 2022 · 1 comment
Open

Output is NaN for a specific date format #1852

nikhil-kumar-160 opened this issue Apr 11, 2022 · 1 comment

Comments

@nikhil-kumar-160
Copy link

Describe the bug
When I try to use dayjs with customParseFormat to parse a string like "20 Nov, 2022" to a date object, It is not able to parse it. I get NaN in return.

Code
dayjs('20 Nov, 2022', DD MMM, YYYY').toDate()

If i remove the comma, present after the Month name, It works fine.

Expected behavior
It should return a date object.

I am using it in a React Native Project.

Information

  • Day.js Version = v1.11.0
  • OS: = iOS
  • Browser [e.g. chrome 62]
  • Time zone: [e.g. GMT+05:30 IST (Indian Standard Time)]
@BePo65
Copy link
Contributor

BePo65 commented May 23, 2022

I could tack the problem down: the comma is not a character that is identified as a separator in customParseFormat plugin.

@iamkun is there a special reason, why comma (or other special characters) are not defined as 'separator' characters in formattingTokens? And why the dot character defined in formattingTokens as separator character is not included in the const matchWord used to parse words (like the name of a month)?

I can easily create a pr for this issue; it is only to add the comma to the 2 constants mentioned above.
I also added some tests to 'customParseFormat.test.js' to identify the problem and to verify the solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants