From 84540b66f5a123627640436e299c7dd89f9c2170 Mon Sep 17 00:00:00 2001 From: Oded Arbel Date: Sat, 5 Sep 2020 12:04:28 +0300 Subject: [PATCH] Fixed dateTime according to OASIS and hack for Excel My bad with previous commit - according to [OASIS 1.2 spec](http://docs.oasis-open.org/office/v1.2/os/OpenDocument-v1.2-os-part1.html#datatype-dateOrDateTime) and [XML Schema part 2](https://www.w3.org/TR/2004/REC-xmlschema-2-20041028/#dateTime), the date time value should always be either UTC or non-timezoned. Since MS-Excel doesn't like time zones in its ODS importer, I'm also removing the time zone value, after converting to UTC and formatting. Tested with LibreOffice and Excel Online. --- src/Spout/Writer/ODS/Manager/WorksheetManager.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Spout/Writer/ODS/Manager/WorksheetManager.php b/src/Spout/Writer/ODS/Manager/WorksheetManager.php index 0f8a5ae..ac38295 100644 --- a/src/Spout/Writer/ODS/Manager/WorksheetManager.php +++ b/src/Spout/Writer/ODS/Manager/WorksheetManager.php @@ -207,8 +207,9 @@ class WorksheetManager implements WorksheetManagerInterface } elseif ($cell->isDate()) { $value = $cell->getValue(); if ($value instanceof \DateTime) { - $data .= ' office:value-type="date" calcext:value-type="date" office:date-value="' . $value->format(\DateTimeInterface::W3C) . '">'; - $data .= '' . $value->format(\DateTimeInterface::W3C) . ''; + $datevalue = substr($value->setTimezone(new \DateTimeZone("UTC"))->format(\DateTimeInterface::W3C),0,-6); + $data .= ' office:value-type="date" calcext:value-type="date" office:date-value="' . $datevalue . '">'; + $data .= '' . $datevalue . ''; } else if ($value instanceof \DateInterval) { // workaround for missing DateInterval::format('c'), see https://stackoverflow.com/a/61088115/53538 static $f = ['M0S', 'H0M', 'DT0H', 'M0D', 'Y0M', 'P0Y', 'Y0M', 'P0M'];