Files
PhpSpreadsheet/tests/data/Shared/Date/ExcelToTimestamp1900.php
oleibman 04e7c30758 Fix Two 32-bit Timestamp Problems, and Minor getFormattedValue Bug (#1891)
I ran the test suite using 32-bit PHP. There were 2 places where changes
were needed due to 32-bit timestamps.

Reader\\Xml.php was using strtotime as an intermediate step in converting
a string timestamp to an Excel timestamp. The XML file type stores pure timestamps
(i.e. no date portion) as, e.g., 1899-12-31T02:30:00.000, and that value
causes an error using strtotime on a 32-bit system. However, it is sufficient
to use that value in a DateTime constructor, and that will work for 32- and 64-bit.

There was no test for that particular cell, so I added one to the XML read test.
And that's when I discovered the getFormattedValue bug. The cell's format
is `hh":"mm":"ss`. The quotes around the colons are disrupting the formatting.
PhpSpreadsheet formats the cell by converting the Excel format
to a Php Date format, in this case `H\:m\:s`.
That's a problem,
since Excel thinks 'm' means *minutes*, but PHP thinks it means *months*.
This is not a problem when the colon is not quoted; there are ample tests for that.
I added my best guess as to how to recognize this situation,
changing `\:m` to `:i`. The XML read test
now succeeds, and no other tests were broken by this change.

Test Shared\\DateTest had one test where the expected result of converting to a
Unix timestamp exceeds 2**32. Since a Unix timestamp is strictly an int,
that test fails on a 32-bit system. In the discussion regarding recently merged
PR #1870, it was felt that the user base might still be using the functions
that convert to and from a timestamp. So, we should not drop this test, but,
since it cannot succeed on a 32-bit system, I changed it to be skipped
whenever the expected result exceeded PHP_INT_MAX. There are 3 "toTimestamp"
functions within that test. Only one of these had been affected, but I thought
it was a good idea to add additional tests to the others to demonstrate this
condition.

In the course of testing, I also discovered some 32-bit problems with
bitwise and base-conversion functions. I am preparing separate PRs to
deal with those.
2021-03-03 10:52:11 +01:00

83 lines
1.3 KiB
PHP

<?php
// Excel DateTimeStamp Result Comments
return [
// PHP 32-bit Earliest Date 14-Dec-1901
[
-2147472000,
714,
],
// 31-Dec-1903
[
-2082931200,
1461,
],
// Excel 1904 Calendar Base Date 01-Jan-1904
[
-2082844800,
1462,
],
// 02-Jan-1904
[
-2082758400,
1463,
],
// 19-Dec-1960
[
-285120000,
22269,
],
// PHP Base Date 01-Jan-1970
[
0,
25569,
],
// 07-Dec-1982
[
408067200,
30292,
],
// 12-Jun-2008
[
1213228800,
39611,
],
// PHP 32-bit Latest Date 9-Jan-2038
[
2147472000,
50424,
],
// 18-May-1903 13:37:46
[
-2102494934,
1234.56789,
],
// 18-Oct-1933 16:17:37
[
-1142494943,
12345.6789,
],
// 12:00:00
[
43200,
0.5,
],
// 18:00.00
[
64800,
0.75,
],
// 02:57:46
[
10666,
0.12345,
],
// 29-Apr-2038 00:00:00 beyond PHP 32-bit Latest Date
[
2156112000,
50524,
],
[-2147483648, -2147483648 / 86400], // Okay on 64- and 32-bit systems
[-2147483649, -2147483649 / 86400], // Skipped test on 32-bit
];