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

Trouble parsing a date field #75

Open
radiospiel opened this issue Apr 7, 2018 · 12 comments
Open

Trouble parsing a date field #75

radiospiel opened this issue Apr 7, 2018 · 12 comments
Assignees

Comments

@radiospiel
Copy link

I have a xlsx file, which has a field with the content "01.05.2018". xlsxir parses this into {2014, 4, 30}. While changing the date from May 1st into Apr 30th could be explained as some timezone adjustment (note that this is Berlin, which is both german - i.e. uses DD.MM.YYYY - and UTC+1/UTC+2) the year change cannot be explained that way.

Any ideas how I could fix this? Is this a bug with xlsxir? I can easily provide the XLSX file if that helps.

@radiospiel
Copy link
Author

Note that I do

[ headers | rows ] = Xlsxir.stream_list(path, 0) |> Enum.map(fn s -> s end)

@jsonkenl
Copy link
Owner

jsonkenl commented Apr 9, 2018

@radiospiel Thanks for letting me know. I'll take a look as soon as possible and get back to you.

@radiospiel
Copy link
Author

thank you, I appreciate that very much!

@jsonkenl
Copy link
Owner

@radiospiel it might help to have the xlsx file as I've been unable to reproduce the error. I've formatted a cell in a new workbook as DD.MM.YYYY and it's parsing it as {2018, 5, 1} for me.

@radiospiel
Copy link
Author

@jsonkenl ah I missed the notification email, thanks for the speedy response :) So, here it is:
forum-bug.xlsx

@radiospiel
Copy link
Author

@jsonkenl I wonder if you found the time to look into this? Any help is greatly appreciated :)

@jsonkenl
Copy link
Owner

@radiospiel My apologies for the delay. I've added this to my to-do for the weekend. I should have something for you soon.

@jsonkenl
Copy link
Owner

Hey @radiospiel, I think it has something to do with your regional date/time settings on your operating system or settings within Excel. I created a custom date field in a new workbook I opened up and the sequential serial number I get from 01.05.2018 using dd.mm.yyyy is '43221' while the sequential serial number from your workbook for the same date is '41759'. Only date formats that begin with an asterisk respond to changes in regional date and time settings. Custom dates to not.

Xlsxir is designed to interpret dates where a serial date of '1' is equal to 1/1/1900. When I convert '1' to a date in your workbook, I get 1/2/1904.

@radiospiel
Copy link
Author

@jsonkenl well, that sounds super weird, but I will pick deeper. If i find something I'll check back with you. In the meantime lets close this issue for now. Thanks for your help!

@radiospiel
Copy link
Author

Me again :) It seems someone else also found out about this, see https://www.accountingweb.com/technology/excel/when-excel-dates-mysteriously-shift-by-4-years

@jsonkenl
Copy link
Owner

@radiospiel Ok, I see it now. When you crack open a .xlsx file, it's made up of a bunch of .xml files (among others). In the workbook.xml file, I found the following line in your workbook: <workbookPr codeName="ThisWorkbook" date1904="1"/>. I should be able to use this line to programmatically check for this issue and then adjust the date calculation accordingly. I'll add it to my todo and will notify you when done.

In the meantime, you can go into "Excel Options > Advanced > When calculating this workbook:" and uncheck the "Use 1904 date system" option to force your workbook to work with Xlsxir.

@jsonkenl jsonkenl reopened this Jun 20, 2018
@jsonkenl jsonkenl self-assigned this Jun 20, 2018
@radiospiel
Copy link
Author

@jsonkenl yea, I did this and it seems to do the trick. An enhancement in xlsxir would make it more awesome still :) Thanks for the good work!

@jsonkenl jsonkenl mentioned this issue Jul 12, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants