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
PHPToExcel::timestampToExcel uses GMT timezone #2347
Comments
The use of Unix timestamps rather than DateTime objects is problematic on many levels. I even suggested deprecating such usage (see PR #1870), although we decided that they were probably still too much in use to do so at this time. Nevertheless, your suggestion to update the doc block might be worthwhile; I will look into it. |
oleibman
added a commit
to oleibman/PhpSpreadsheet
that referenced
this issue
Oct 24, 2021
This was suggested by issue PHPOffice#2347. Unix timestamps have clear disadvantages compared with the alternate methods of supplying date and time to PhpSpreadsheet - DateTime objects, Excel date time fields, and strings. In particular, Unix timestamp is not Y2038-safe on a 32-bit system, and it reflects the time in UTC, which may come as a surprise to the end-user (as it did in the cited issue). The alternate methods do not come with such baggage. This change updates some doc blocks to note that Unix timestamps are discoburage (N.B. - not deprecated). No executable code is changed.
5 tasks
oleibman
added a commit
that referenced
this issue
Nov 4, 2021
* Update Doc Blocks to Discourage Use of Unix Timestamps This was suggested by issue #2347. Unix timestamps have clear disadvantages compared with the alternate methods of supplying date and time to PhpSpreadsheet - DateTime objects, Excel date time fields, and strings. In particular, Unix timestamp is not Y2038-safe on a 32-bit system, and it reflects the time in UTC, which may come as a surprise to the end-user (as it did in the cited issue). The alternate methods do not come with such baggage. This change updates some doc blocks to note that Unix timestamps are discoburage (N.B. - not deprecated). No executable code is changed. * Document in Code As Well as Commmit Message Per suggestion from @PowerKiKi. * Missed One DocBlock Including it now. Co-authored-by: Adrien Crivelli <adrien.crivelli@gmail.com>
Documentation updated by 2350, as requested. Closing. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is:
What is the expected behavior?
I am using the
Date::PHPToExcel($ts);
with a unix timestamp and was wondering why the timezone which i set wasn't used.What is the current behavior?
My current timezone set in my application is 'Europe\Berlin' i add some cells with datetimes to the Excel file and the Timezone of those fields isn't correct when i used unix timestamps.
What are the steps to reproduce?
Output
Problem comes from this function in Shared/Date.php which creates the dates when a timestamp is given to PHPToExcel.
The DateTime constructor ignores any Timezones for UNIX timestamp.
Wouldn't it be more
correct
if the function creates the Datetime in the timezone which was set byDate::setDefaultTimezone
and is returned byDate::getDefaultTimezone
?e.g. modify the timestampToExcel to use this default Timezone or PHP's default Timezone?
This issue was also discussed here:
#611
Or at least add some text to the documentation that the function does work differently for Unix Timestamps as nothing is mentioned there:
https://phpoffice.github.io/PhpSpreadsheet/classes/PhpOffice-PhpSpreadsheet-Shared-Date.html#method_PHPToExcel
The text was updated successfully, but these errors were encountered: