1
0
mirror of https://github.com/rlanvin/php-rrule.git synced 2025-02-20 09:54:16 +01:00

rfcString() formats DTSTART with a Z

This commit is contained in:
rlanvin 2016-06-30 13:27:06 +03:00
parent 97d860e55e
commit cb5735edd9
2 changed files with 21 additions and 7 deletions

View File

@ -523,11 +523,19 @@ class RRule implements RRuleInterface
{
$str = '';
if ( $this->rule['DTSTART'] ) {
$str = sprintf(
"DTSTART;TZID=%s:%s\nRRULE:",
$this->dtstart->getTimezone()->getName(),
$this->dtstart->format('Ymd\THis')
);
if ( $this->dtstart->getTimeZone()->getName() == 'Z' ) {
$str = sprintf(
"DTSTART:%s\nRRULE:",
$this->dtstart->format('Ymd\THis\Z')
);
}
else {
$str = sprintf(
"DTSTART;TZID=%s:%s\nRRULE:",
$this->dtstart->getTimezone()->getName(),
$this->dtstart->format('Ymd\THis')
);
}
}
$parts = array();
@ -542,8 +550,7 @@ class RRule implements RRuleInterface
continue;
}
if ( $key === 'UNTIL' && $value ) {
// for a reason that I do not understand, UNTIL seems to always
// be in UTC (even when DTSTART includes TZID)
// according to the RFC, UNTIL must be in UTC
$tmp = clone $this->until;
$tmp->setTimezone(new \DateTimeZone('UTC'));
$parts[] = 'UNTIL='.$tmp->format('Ymd\THis\Z');

View File

@ -1779,6 +1779,13 @@ class RRuleTest extends PHPUnit_Framework_TestCase
$rule = new RRule($str);
}
public function testRfcStringWithUTC()
{
$rule = new RRule('DTSTART:19970512T090000Z
RRULE:FREQ=YEARLY');
$this->assertEquals("DTSTART:19970512T090000Z\nRRULE:FREQ=YEARLY", $rule->rfcString());
}
///////////////////////////////////////////////////////////////////////////////
// Timezone