diff --git a/src/Spout/Reader/XLSX/Helper/CellValueFormatter.php b/src/Spout/Reader/XLSX/Helper/CellValueFormatter.php index a272a2e..2a9d398 100644 --- a/src/Spout/Reader/XLSX/Helper/CellValueFormatter.php +++ b/src/Spout/Reader/XLSX/Helper/CellValueFormatter.php @@ -283,16 +283,16 @@ class CellValueFormatter /** * Returns a cell's PHP Date value, associated to the given stored nodeValue. + * @see ECMA-376 Part 1 - ยง18.17.4 * - * @param string $nodeValue - * @return \DateTime|null The value associated with the cell or NULL if invalid date value + * @param string $nodeValue ISO 8601 Date string + * @return \DateTime|string|null The value associated with the cell or NULL if invalid date value */ protected function formatDateCellValue($nodeValue) { // Mitigate thrown Exception on invalid date-time format (http://php.net/manual/en/datetime.construct.php) try { - $cellValue = new \DateTime($nodeValue); - return $cellValue; + return ($this->shouldFormatDates) ? $nodeValue : new \DateTime($nodeValue); } catch (\Exception $e) { return null; } diff --git a/tests/Spout/Reader/XLSX/ReaderTest.php b/tests/Spout/Reader/XLSX/ReaderTest.php index 02c91ed..0deb84c 100644 --- a/tests/Spout/Reader/XLSX/ReaderTest.php +++ b/tests/Spout/Reader/XLSX/ReaderTest.php @@ -274,6 +274,7 @@ class ReaderTest extends \PHPUnit_Framework_TestCase $expectedRows = [ ['1/13/2016', '01/13/2016', '13-Jan-16', 'Wednesday January 13, 16', 'Today is 1/13/2016'], ['4:43:25', '04:43', '4:43', '4:43:25 AM', '4:43:25 PM'], + ['1976-11-22T08:30:00.000', '1976-11-22T08:30', '1582-10-15', '08:30:00', '08:30'], ]; $this->assertEquals($expectedRows, $allRows); } diff --git a/tests/resources/xlsx/sheet_with_dates_and_times.xlsx b/tests/resources/xlsx/sheet_with_dates_and_times.xlsx index 769e03b..b73d65a 100644 Binary files a/tests/resources/xlsx/sheet_with_dates_and_times.xlsx and b/tests/resources/xlsx/sheet_with_dates_and_times.xlsx differ