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

"2-020-00" treated as a Date in Chrome, but not Firefox or Safari #98

Open
dahjelle opened this issue Aug 13, 2020 · 1 comment
Open

Comments

@dahjelle
Copy link

I was using natural-orderby to try compare "2-020-00" and "3-000-00", and found that Firefox produced the expected ordering, while Chrome did not.

compare()("2-020-00", "3-000-00"); // 1 in Chrome, -1 in Firefox and Safari

I believe this is because Date.parse('2-020-00'); yields 951026400000 in Chrome, but NaN in Firefox and Safari.

I realize this is a browser difference that would be rather hard to fix. MDN even recommends against Date.parse for presumably that reason. But in case you had any ideas, I thought I'd post it here. :-D

@dahjelle
Copy link
Author

dahjelle commented Jan 8, 2021

A fix for this could be adjusting the RE_DATE regular expression somewhat. It currently is looking for a pattern of 1-4 digits, dash, 1-4 digits, dash, 1-4 digits. If that is changed so that the middle set of digits cannot be longer than 2 digits, that helps my specific case. I don't know if that's invalid for other date formats or not.

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

1 participant