diff --git a/library/Icingadb/Data/CsvResultSet.php b/library/Icingadb/Data/CsvResultSet.php index 24e34a674..cab6aec16 100644 --- a/library/Icingadb/Data/CsvResultSet.php +++ b/library/Icingadb/Data/CsvResultSet.php @@ -4,6 +4,8 @@ namespace Icinga\Module\Icingadb\Data; +use DateTime; +use DateTimeZone; use ipl\Orm\Model; use ipl\Orm\Query; use ipl\Orm\ResultSet; @@ -17,7 +19,7 @@ public function current() return $this->extractKeysAndValues(parent::current()); } - protected function formatValue(string $key, ?string $value): ?string + protected function formatValue(string $key, $value): ?string { if ( $value @@ -38,6 +40,9 @@ protected function formatValue(string $key, ?string $value): ?string return '"' . str_replace('"', '""', $value) . '"'; } elseif (is_array($value)) { return '"' . implode(',', $value) . '"'; + } elseif ($value instanceof DateTime) { + return $value->setTimezone(new DateTimeZone('UTC')) + ->format('Y-m-d\TH:i:s.vP'); } else { return $value; } diff --git a/library/Icingadb/Data/JsonResultSet.php b/library/Icingadb/Data/JsonResultSet.php index e0eb6236e..f174e21d6 100644 --- a/library/Icingadb/Data/JsonResultSet.php +++ b/library/Icingadb/Data/JsonResultSet.php @@ -4,6 +4,8 @@ namespace Icinga\Module\Icingadb\Data; +use DateTime; +use DateTimeZone; use Icinga\Util\Json; use ipl\Orm\Model; use ipl\Orm\Query; @@ -18,7 +20,7 @@ public function current() return $this->createObject(parent::current()); } - protected function formatValue(string $key, ?string $value): ?string + protected function formatValue(string $key, $value): ?string { if ( $value @@ -33,6 +35,11 @@ protected function formatValue(string $key, ?string $value): ?string $value = bin2hex($value); } + if ($value instanceof DateTime) { + return $value->setTimezone(new DateTimeZone('UTC')) + ->format('Y-m-d\TH:i:s.vP'); + } + return $value; }