Skip to content

Fix issue # 991 #1019

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

Merged
merged 4 commits into from
Nov 5, 2019
Merged

Fix issue # 991 #1019

merged 4 commits into from
Nov 5, 2019

Conversation

LibertyNJ
Copy link
Contributor

There is an issue where the csv.read/readFile method will incorrectly parse certain strings as dates that should not be dates. This may stem from differences in the API of momentjs and dayjs that were not addressed after migration.

By default dayjs will transform any string that matches the regex /^\d{4}-?\d/ into a valid date, whether it makes sense for that string to be interpreted as a date or not. This appears to be intended behavior on the part of dayjs, as it lets the module parse dates from strings in non-standard formats. If this is not the intended behavior of the csv.read/readFile methods, the default options.map method needs some more logic to help decide when to return a date.

Proves that the current implementation of csv.readFile parses strings
that satisfy the regex /^\d{4}-?\d/ as if they were dates.
Passes tests for issue 991. Dayjs and momentjs do not have identical
APIs. Original implementation of dayjs substituted all references to
"momentjs" with "dayjs". There is no dayjs.ISO_8601 constant. Dayjs
must be extended with a plugin to customize date parsing format. Dayjs
does not accept an array of date formats as an argument.
Adjusts default dateFormat strings to be aligned with intended
default behavior.
@guyonroche guyonroche merged commit eda23ae into exceljs:master Nov 5, 2019
@damianaiamad
Copy link

I'm a bit late to this party, sorry. I think I've identified a further problem with dayjs that means this fix does not fully solve the problem.

Please see #991

@LibertyNJ
Copy link
Contributor Author

Can confirm, 'D/M/YY' pattern breaks test with 'NZ1019316'. Dayjs appears to have further issues as @damianaiamad identified in #991.

Reverting to moment is definitely a solution (wasn't broke, why fix it?), if the size of that module is not still a concern as it was in issue #794.

@damianaiamad
Copy link

damianaiamad commented Nov 21, 2019

One advantage of @LibertyNJ's solution is that it allows turning off automatic date parsing as follows:

workbook.csv.read(stream, {dateFormats: []})

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

Successfully merging this pull request may close these issues.

3 participants