diff --git a/lib/Property/ICalendar/Period.php b/lib/Property/ICalendar/Period.php index 7632cb4d..c27da35c 100644 --- a/lib/Property/ICalendar/Period.php +++ b/lib/Property/ICalendar/Period.php @@ -72,6 +72,10 @@ function ($item) { parent::setJsonValue($value); } + function appendUtc($strDate) { + return strpos($strDate, 'Z') === false ? '' : 'Z'; + } + /** * Returns the value, in the format it should be encoded for json. * @@ -85,19 +89,19 @@ public function getJsonValue(): array foreach ($this->getParts() as $item) { list($start, $end) = explode('/', $item, 2); - $start = DateTimeParser::parseDateTime($start); - // This is a duration value. - if ('P' === $end[0]) { + $startDt = DateTimeParser::parseDateTime($start)->format('Y-m-d\\TH:i:s') . $this->appendUtc($start); + + if ($end[0] === 'P') { $return[] = [ - $start->format('Y-m-d\\TH:i:s'), - $end, + $startDt, + $end ]; } else { - $end = DateTimeParser::parseDateTime($end); + $endDt = DateTimeParser::parseDateTime($end)->format('Y-m-d\\TH:i:s') . $this->appendUtc($end); $return[] = [ - $start->format('Y-m-d\\TH:i:s'), - $end->format('Y-m-d\\TH:i:s'), + $startDt, + $endDt ]; } } diff --git a/tests/VObject/JCalTest.php b/tests/VObject/JCalTest.php index fa347966..7624b8f8 100644 --- a/tests/VObject/JCalTest.php +++ b/tests/VObject/JCalTest.php @@ -97,7 +97,7 @@ public function testToJCal(): void 'sequence', new \stdClass(), 'integer', 5, ], [ - 'freebusy', new \stdClass(), 'period', ['2013-05-26T21:02:13', 'PT1H'], ['2013-06-26T12:00:00', '2013-06-26T13:00:00'], + 'freebusy', new \stdClass(), 'period', ['2013-05-26T21:02:13Z', 'PT1H'], ['2013-06-26T12:00:00Z', '2013-06-26T13:00:00Z'], ], [ 'url', new \stdClass(), 'uri', 'http://example.org/', diff --git a/tests/VObject/Parser/JsonTest.php b/tests/VObject/Parser/JsonTest.php index 392cc7c1..dacfb3b5 100644 --- a/tests/VObject/Parser/JsonTest.php +++ b/tests/VObject/Parser/JsonTest.php @@ -261,7 +261,7 @@ public function testRoundTripJCal(): void 'sequence', new \stdClass(), 'integer', 5, ], [ - 'freebusy', new \stdClass(), 'period', ['2013-05-26T21:02:13', 'PT1H'], ['2013-06-26T12:00:00', '2013-06-26T13:00:00'], + 'freebusy', new \stdClass(), 'period', ['2013-05-26T21:02:13Z', 'PT1H'], ['2013-06-26T12:00:00Z', '2013-06-26T13:00:00Z'], ], [ 'url', new \stdClass(), 'uri', 'http://example.org/', diff --git a/tests/VObject/Parser/XmlTest.php b/tests/VObject/Parser/XmlTest.php index 6491d087..f8b37f5c 100644 --- a/tests/VObject/Parser/XmlTest.php +++ b/tests/VObject/Parser/XmlTest.php @@ -684,7 +684,7 @@ public function testRFC6321Section3Part6Part9(): void - 2011-05-17T12:00:00 + 2011-05-17T12:00:00Z P1H @@ -693,7 +693,7 @@ public function testRFC6321Section3Part6Part9(): void XML, 'BEGIN:VCALENDAR'."\n". - 'FREEBUSY:20110517T120000/P1H'."\n". + 'FREEBUSY:20110517T120000Z/P1H'."\n". 'END:VCALENDAR'."\n" ); @@ -705,8 +705,8 @@ public function testRFC6321Section3Part6Part9(): void - 2011-05-17T12:00:00 - 2012-05-17T12:00:00 + 2011-05-17T12:00:00Z + 2012-05-17T12:00:00Z @@ -714,7 +714,7 @@ public function testRFC6321Section3Part6Part9(): void XML, 'BEGIN:VCALENDAR'."\n". - 'FREEBUSY:20110517T120000/20120517T120000'."\n". + 'FREEBUSY:20110517T120000Z/20120517T120000Z'."\n". 'END:VCALENDAR'."\n" ); }