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

Invalid date recognition #1646

Closed
krojew opened this issue Sep 30, 2019 · 4 comments
Closed

Invalid date recognition #1646

krojew opened this issue Sep 30, 2019 · 4 comments

Comments

@krojew
Copy link

krojew commented Sep 30, 2019

fuzzydate() function incorrectly guesses date due to invalid regex pattern. For example, let's look at "Trollahaugen 64" text. First, it tries to convert it to date and it ends up being 01.01.1964 due to 64 at the end. Then it proceeds with looking for a month using /jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec/ regex. This is the source of error, since the text contains "aug" inside but it's not a separate word, hence should not be considered a month. Yet, the function assumes it is and returns 01.01.1964.

@SheetJSDev
Copy link
Contributor

Just so we're on the same page: the root problem is the incredible flexibility of the Date constructor in V8 and other JS engines. In chrome, new Date("Trollahaugen 64") is interpreted as the beginning of the year 1964 (Jan 1 0:00 local time).

There are a handful of workarounds for common cases we've seen but it's not pretty. The "right" answer is to skip the date constructor entirely and just regex against a series of culture-specific formats

@krojew
Copy link
Author

krojew commented Sep 30, 2019

I understand the inherent problem with solving such issue - there always will be some edge cases. Working around this particular one seems to be trivial - simply expect the month name to be a whole word, surrounded with non-alphabetic characters, if we assume (which might not be true) that the string is a ECMA-262 Date.toString() representation.

@tophsic
Copy link

tophsic commented Oct 19, 2020

Hi, I had a similar issue with "SEPEM GRENOBLE 2018" text which is transformed in 9/1/18 date.

@SheetJSDev
Copy link
Contributor

Moving the discussion to #1300

@krojew The spec uses the phrase "implementation-dependent":

in general, the value produced by Date.parse is implementation-dependent when given any String value that does not conform to the Date Time String Format

That Date Time String Format is related to ISO 8601 and does not cover the set of date expressions understood by Excel

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

3 participants