From 6c4086cf97b36f0ca87d19f051902ce8004ee6b0 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 dd609cb2..42f287d1 100644 --- a/src/Spout/Reader/XLSX/Manager/SheetManager.php +++ b/src/Spout/Reader/XLSX/Manager/SheetManager.php @@ -114,7 +114,9 @@ public function getSheets() */ 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;