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

Date datatype converts date => datetime #262

Closed
scottsteinbeck opened this issue Oct 1, 2021 · 6 comments
Closed

Date datatype converts date => datetime #262

scottsteinbeck opened this issue Oct 1, 2021 · 6 comments

Comments

@scottsteinbeck
Copy link

Reproducible use case

  data = QueryNew( "Date", "VarChar", [ [  "2020-08-24" ] ] );
  datatypes = { date: [ "Date" ] };
  spreadsheet = New spreadsheet();
  workbook = spreadsheet.new();
  spreadsheet.addRows( workbook=workbook, data=data, datatypes=datatypes );

Screen Shot 2021-10-01 at 12 46 08 AM

You can see that before it was a date with no time. after setting the datatype, the date now has a time of 7:00:00 AM

@cfsimplicity
Copy link
Owner

Hi Scott

Running your code I get different results. The value is showing as a date with no time in both Excel...

20211001-excel
...and Libre Office

20211001-libre

Dates are actually stored as numbers in excel, whole ones for date only values, with fractions added for times.

To check what is actually being recorded in your workbook object, try adding the following code to your test case:

WriteDump( spreadsheet.getCellType( workbook, 1, 1 ) );
WriteDump( spreadsheet.getCellValue( workbook, 1, 1 ) );
spreadsheet.formatCell( workbook, { dataformat: "0.00000" }, 1, 1 );
WriteDump( spreadsheet.getCellValue( workbook, 1, 1 ) );

This is what I'm seeing, i.e. definitely a whole number, no time fractions:

20211001-dump

What do you get?

@scottsteinbeck
Copy link
Author

I will say that i updated my timezone to reflect PST, I wonder if this is causing the issue. Though with a static date it shouldnt.
Screen Shot 2021-10-01 at 9 54 57 AM

@scottsteinbeck
Copy link
Author

Confirmed! Upon testing resetting the timezone inside lucee admin to the default (same as server), it has corrected the numeric value of the date
image

@scottsteinbeck
Copy link
Author

I would assume this is a lucee issue and not a library issue correct?

@cfsimplicity
Copy link
Owner

I'm not sure it's necessarily either, although it's complicated and adding timezones into the mix makes it more so! I'm not an expert in this, but here's my current partial understanding.

The cell types the library lets you specify are string, numeric, date, time, boolean and auto.

date and time both actually translate to a datetime value, since that's all CF/POI/Excel understand.

The library will however try to identify "date only" and "time only" values and set the cell format to only display those portions of the datetime value in the cell. But the underlying datetime value is still stored in Excel as a number as explained above.

I don't fully understand the effect of changing the Lucee timezone, but I believe that POI/Excel uses the local machine timezone, so if there is a mismatch that will affect what POI stores.

Apparently POI does provide a way of specifying the timezone. I'll have a look at whether that could be a potential solution.

@cfsimplicity
Copy link
Owner

Forcing POI to match the Lucee timezone when setting date values does seem to fix the issue according to my tests.

Please check with the latest develop branch, Scott, and if it's still not working for you just re-open the ticket.

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

2 participants