Add support for 1904 dates
This commit adds support for dates using the 1904 calendar (starting 1904-01-01 00:00:00). It also fixes some issues with the dates in 1900 calendar (which now correctly start at 1899-12-30 00:00:00). Finally, it is now possible to have negative timestamps, representing dates before the base date (and up to 0000-01-01 00:00:00), as per the SpreadsheetML specs. Note that some versions of Excel don't support negative dates...
This commit is contained in:
1 parent
e1ae3c8a81
commit
c74c0d9127
9 files changed
+194
-102
No files matched your search
@@ -231,9 +231,34 @@ class ReaderTest extends \PHPUnit_Framework_TestCase
|
||||
\DateTime::createFromFormat('Y-m-d H:i:s', '2015-09-01 22:23:00'),
|
||||
],
|
||||
[
|
||||
\DateTime::createFromFormat('Y-m-d H:i:s', '1900-02-28 23:59:59'),
|
||||
\DateTime::createFromFormat('Y-m-d H:i:s', '1900-02-27 23:59:59'),
|
||||
\DateTime::createFromFormat('Y-m-d H:i:s', '1900-03-01 00:00:00'),
|
||||
\DateTime::createFromFormat('Y-m-d H:i:s', '1900-02-28 11:00:00'), // 1900-02-29 should be converted to 1900-02-28
|
||||
\DateTime::createFromFormat('Y-m-d H:i:s', '1900-02-28 11:00:00'),
|
||||
],
|
||||
];
|
||||
$this->assertEquals($expectedRows, $allRows);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testReadShouldSupportDifferentDatesAsNumericTimestampWith1904Calendar()
|
||||
{
|
||||
// make sure dates are always created with the same timezone
|
||||
date_default_timezone_set('UTC');
|
||||
|
||||
$allRows = $this->getAllRowsForFile('sheet_with_different_numeric_value_dates_1904_calendar.xlsx');
|
||||
|
||||
$expectedRows = [
|
||||
[
|
||||
\DateTime::createFromFormat('Y-m-d H:i:s', '2019-09-02 00:00:00'),
|
||||
\DateTime::createFromFormat('Y-m-d H:i:s', '2019-09-03 00:00:00'),
|
||||
\DateTime::createFromFormat('Y-m-d H:i:s', '2019-09-02 22:23:00'),
|
||||
],
|
||||
[
|
||||
\DateTime::createFromFormat('Y-m-d H:i:s', '1904-02-29 23:59:59'),
|
||||
\DateTime::createFromFormat('Y-m-d H:i:s', '1904-03-02 00:00:00'),
|
||||
\DateTime::createFromFormat('Y-m-d H:i:s', '1904-03-01 11:00:00'),
|
||||
],
|
||||
];
|
||||
$this->assertEquals($expectedRows, $allRows);
|
||||
@@ -251,11 +276,11 @@ class ReaderTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
$expectedRows = [
|
||||
[
|
||||
\DateTime::createFromFormat('Y-m-d H:i:s', '1900-01-01 00:00:00'),
|
||||
\DateTime::createFromFormat('Y-m-d H:i:s', '1900-01-01 11:29:00'),
|
||||
\DateTime::createFromFormat('Y-m-d H:i:s', '1900-01-01 23:29:00'),
|
||||
\DateTime::createFromFormat('Y-m-d H:i:s', '1900-01-01 01:42:25'),
|
||||
\DateTime::createFromFormat('Y-m-d H:i:s', '1900-01-01 13:42:25'),
|
||||
\DateTime::createFromFormat('Y-m-d H:i:s', '1899-12-30 00:00:00'),
|
||||
\DateTime::createFromFormat('Y-m-d H:i:s', '1899-12-30 11:29:00'),
|
||||
\DateTime::createFromFormat('Y-m-d H:i:s', '1899-12-30 23:29:00'),
|
||||
\DateTime::createFromFormat('Y-m-d H:i:s', '1899-12-30 01:42:25'),
|
||||
\DateTime::createFromFormat('Y-m-d H:i:s', '1899-12-30 13:42:25'),
|
||||
],
|
||||
];
|
||||
$this->assertEquals($expectedRows, $allRows);
|
||||
|
||||
Reference in new issue
Block a user