From 726e0d6a78fad194a943d3d0b752ff7f46a31d45 Mon Sep 17 00:00:00 2001 From: Adrien Loison Date: Mon, 3 Jun 2019 13:49:55 +0200 Subject: [PATCH] Fix reading of 1904 dates option Whether the spreadsheet is using 1904 dates or not is controlled by a XML property. Its value can be the string "false" that is not mapped to the boolean "false" but to the boolean "true"... Therefore Spout was previously using the wrong date system when this property was set. --- src/Spout/Reader/XLSX/Manager/SheetManager.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Spout/Reader/XLSX/Manager/SheetManager.php b/src/Spout/Reader/XLSX/Manager/SheetManager.php index dd609cb..42f287d 100644 --- a/src/Spout/Reader/XLSX/Manager/SheetManager.php +++ b/src/Spout/Reader/XLSX/Manager/SheetManager.php @@ -114,7 +114,9 @@ class SheetManager */ protected function processWorkbookPropertiesStartingNode($xmlReader) { - $shouldUse1904Dates = (bool) $xmlReader->getAttribute(self::XML_ATTRIBUTE_DATE_1904); + // Using "filter_var($x, FILTER_VALIDATE_BOOLEAN)" here because the value of the "date1904" attribute + // may be the string "false", that is not mapped to the boolean "false" by default... + $shouldUse1904Dates = filter_var($xmlReader->getAttribute(self::XML_ATTRIBUTE_DATE_1904), FILTER_VALIDATE_BOOLEAN); $this->optionsManager->setOption(Options::SHOULD_USE_1904_DATES, $shouldUse1904Dates); return XMLProcessor::PROCESSING_CONTINUE;