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.
This commit is contained in:
Oded Arbel authored and GitHub committed 2020-09-05 12:04:28 +03:00
1 parent 1c1b3ed5c9
commit 84540b66f5
1 file changed
+3 -2
@@ -207,8 +207,9 @@ class WorksheetManager implements WorksheetManagerInterface
} elseif ($cell->isDate()) { } elseif ($cell->isDate()) {
$value = $cell->getValue(); $value = $cell->getValue();
if ($value instanceof \DateTime) { if ($value instanceof \DateTime) {
$data .= ' office:value-type="date" calcext:value-type="date" office:date-value="' . $value->format(\DateTimeInterface::W3C) . '">'; $datevalue = substr($value->setTimezone(new \DateTimeZone("UTC"))->format(\DateTimeInterface::W3C),0,-6);
$data .= '<text:p>' . $value->format(\DateTimeInterface::W3C) . '</text:p>'; $data .= ' office:value-type="date" calcext:value-type="date" office:date-value="' . $datevalue . '">';
$data .= '<text:p>' . $datevalue . '</text:p>';
} else if ($value instanceof \DateInterval) { } else if ($value instanceof \DateInterval) {
// workaround for missing DateInterval::format('c'), see https://stackoverflow.com/a/61088115/53538 // workaround for missing DateInterval::format('c'), see https://stackoverflow.com/a/61088115/53538
static $f = ['M0S', 'H0M', 'DT0H', 'M0D', 'Y0M', 'P0Y', 'Y0M', 'P0M']; static $f = ['M0S', 'H0M', 'DT0H', 'M0D', 'Y0M', 'P0Y', 'Y0M', 'P0M'];