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:
parent
1c1b3ed5c9
commit
84540b66f5
@ -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 .= '<text:p>' . $value->format(\DateTimeInterface::W3C) . '</text:p>';
|
||||
$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 .= '<text:p>' . $datevalue . '</text:p>';
|
||||
} 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'];
|
||||
|
Loading…
x
Reference in New Issue
Block a user