Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions lib/Property/ICalendar/Period.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand All @@ -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
];
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/VObject/JCalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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/',
Expand Down
2 changes: 1 addition & 1 deletion tests/VObject/Parser/JsonTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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/',
Expand Down
10 changes: 5 additions & 5 deletions tests/VObject/Parser/XmlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -684,7 +684,7 @@ public function testRFC6321Section3Part6Part9(): void
<properties>
<freebusy>
<period>
<start>2011-05-17T12:00:00</start>
<start>2011-05-17T12:00:00Z</start>
<duration>P1H</duration>
</period>
</freebusy>
Expand All @@ -693,7 +693,7 @@ public function testRFC6321Section3Part6Part9(): void
</icalendar>
XML,
'BEGIN:VCALENDAR'."\n".
'FREEBUSY:20110517T120000/P1H'."\n".
'FREEBUSY:20110517T120000Z/P1H'."\n".
'END:VCALENDAR'."\n"
);

Expand All @@ -705,16 +705,16 @@ public function testRFC6321Section3Part6Part9(): void
<properties>
<freebusy>
<period>
<start>2011-05-17T12:00:00</start>
<end>2012-05-17T12:00:00</end>
<start>2011-05-17T12:00:00Z</start>
<end>2012-05-17T12:00:00Z</end>
</period>
</freebusy>
</properties>
</vcalendar>
</icalendar>
XML,
'BEGIN:VCALENDAR'."\n".
'FREEBUSY:20110517T120000/20120517T120000'."\n".
'FREEBUSY:20110517T120000Z/20120517T120000Z'."\n".
'END:VCALENDAR'."\n"
);
}
Expand Down
Loading