From e87282516d95352e8eb401556338db704b5a23ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartosz=20W=C3=B3jcik?= Date: Wed, 20 Apr 2016 13:55:32 +0200 Subject: [PATCH] quickfix for #193 for cells formatted as time --- src/Spout/Reader/XLSX/Helper/CellValueFormatter.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/Spout/Reader/XLSX/Helper/CellValueFormatter.php b/src/Spout/Reader/XLSX/Helper/CellValueFormatter.php index e63384d..3b3b191 100644 --- a/src/Spout/Reader/XLSX/Helper/CellValueFormatter.php +++ b/src/Spout/Reader/XLSX/Helper/CellValueFormatter.php @@ -189,7 +189,17 @@ class CellValueFormatter // The value 1.0 represents 1900-01-01. Numbers below 1.0 are not valid Excel dates. if ($nodeValue < 1.0) { - return null; + // treat this value as time-only cell + $time = round($nodeValue * 86400); + $hours = round($time / 3600); + $minutes = round($time / 60) - ($hours * 60); + $seconds = round($time) - ($hours * 3600) - ($minutes * 60); + + // the date part is not important here + $dateObj = date_create('1-Jan-2000'); + $dateObj->setTime($hours,$minutes,$seconds); + + return $dateObj; } // Do not use any unix timestamps for calculation to prevent