Parsing string values and treating as dates is incorrect
See original GitHub issueHi! There is a CSV file, which I try to read and it contains field with value
“Aprobil P 0.1%”
the short example of CSV:
"Country";"Product Family"
"Germany";"Aprobil P 0.1%"
conversion to workbook is the following:
var workbook = XLSX.read(csvData, {
type:'string',
dateNF: 'D-M-YYYY',
cellDates:true,
cellText:true,
cellNF: false,
raw:false});
after conversion I save the XLS, where value “Aprobil P 0.1%” is converted to a date 01.04.00
looking into the worksheet model and getting the certain cell, it contains:
{
t: 'd',
v: 'Sat Apr 01 2000 00:00:00 GMT+0300 (Eastern European Summer Time)',
z:undefined
}
is there any way to cover this case? Could you pls assist, what to do.
Thanks in advance!
Issue Analytics
- State:
- Created 5 years ago
- Comments:13 (5 by maintainers)
Top Results From Across the Web
Why does Date.parse give incorrect results? - Stack Overflow
Now date and time strings without a timezone use the host timezone offset (i.e. "local"). Confusingly, ISO 8601 date only forms are treated...
Read more >6 Ways to Fix Dates Formatted as Text in Excel
6 ways to fix dates formatted ast text in Excel, plus a bonus technique using Power Query to fix various formats.
Read more >Date incorrect parsing from Excel - CloverCARE Support
If I define metadata as Date, it reads the Date without additional value in the front. Strange - it reads the value as...
Read more >Date.parse() - JavaScript - MDN Web Docs
Unrecognizable strings or dates containing illegal element values in ISO formatted strings shall cause Date.parse() to return NaN . However, invalid values ......
Read more >Defeating Automatic Date Parsing in Excel - Causal
In summary, automatic date parsing can cause problems in Excel because dates can be interpreted incorrectly or converted to a different format. To...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hello @pzhelnov ! First, understand that this is an open source project and all work done on the project is charity. If you are concerned about response time or interested in supporting development, we offer paid builds and support as discussed in https://sheetjs.com/pro
That said, unfortunately there’s no magic solution here. The Date parsing currently falls back on the JS Date builtin features, which are super flexible in chrome. As an example:
is the date January 1 2001, despite it clearly indicating that it isn’t a date.
Setting the option
raw: true
will give you the raw strings, suppressing any sort of value interpretation.If you are interested in helping, the relevant function is
fuzzydate
. Google Docs / Office Online likely use a series of regular expressions based on some known formats like/\d{4}-\d{2}-\d{2}/
foryyyy-mm-dd
and that might be a more sensible approach than using the generic Date constructorBased on some testing, in the
en-US
locale, there appear to be no valid Excel dates that contain letters outside of the month short or long names (even full day names are not accepted). Looking at a number of the issues, a guard like(where
lower_months
is an array of the long names of months) would address many of the problems. The proposed “strict” mode is still needed for determining field values and matching formats that Chrome does not accept (for example,1:23.04:56
)