vobject icon indicating copy to clipboard operation
vobject copied to clipboard

VTimezone: DAYLIGHT and STANDARD in the same timezone

Open roelmonnens opened this issue 8 years ago • 3 comments

Hey, When I put DAYLIGHT and STANDARD in de same timezone like this:

$vcalendar         = new VCalendar();
$vcalendar->PRODID = 'test';

$vtimezone = $vcalendar->add('VTIMEZONE', [
    'TZID'           => 'Europe/Brussels',
    'X-LIC-LOCATION' => 'Europe/Brussels'
]);
$vtimezone->add('BEGIN', 'STANDARD');
$vtimezone->add('TZOFFSETFROM', '+0200');
$vtimezone->add('TZOFFSETTO', '+0100');
$vtimezone->add('TZNAME', 'CET');
$vtimezone->add('DTSTART', (new \DateTime('1970-10-25 03:00:00', new \DateTimeZone('Europe/Brussels')))->format('Ymd\THis'));
$vtimezone->add('RRULE', 'FREQ=YEARLY;BYMONTH=10;BYDAY=-1SU');
$vtimezone->add('END', 'STANDARD');

$vtimezone->add('BEGIN', 'DAYLIGHT');
$vtimezone->add('TZOFFSETFROM', '+0100');
$vtimezone->add('TZOFFSETTO', '+0200');
$vtimezone->add('TZNAME', 'CEST');
$vtimezone->add('DTSTART', (new \DateTime('1970-03-29 02:00:00', new \DateTimeZone('Europe/Brussels')))->format('Ymd\THis'));
$vtimezone->add('RRULE', 'FREQ=YEARLY;BYMONTH=3;BYDAY=-1SU');
$vtimezone->add('END', 'DAYLIGHT');
echo $vcalendar->serialize();

I get this result:

BEGIN:VCALENDAR 
VERSION:2.0 
CALSCALE:GREGORIAN 
PRODID:test
BEGIN:VTIMEZONE 
TZID:Europe/Brussels 
X-LIC-LOCATION:Europe/Brussels 
BEGIN:DAYLIGHT 
BEGIN:STANDARD
TZOFFSETFROM:+0100 
TZOFFSETFROM:+0200 
TZOFFSETTO:+0200 
TZOFFSETTO:+0100 
TZNAME:CEST TZNAME:CET 
DTSTART:19700329T020000 
DTSTART:19701025T030000 
RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=-1SU 
RRULE:FREQ=YEARLY;BYMONTH=10;BYDAY=-1SU 
END:DAYLIGHT 
END:STANDARD
END:VTIMEZONE 
END:VCALENDAR

Notice BEGIN:DAYLIGHT BEGIN:STANDARD

This should actually be:

BEGIN:VCALENDAR 
VERSION:2.0 
CALSCALE:GREGORIAN 
PRODID:test
BEGIN:VTIMEZONE 
TZID:Europe/Brussels 
X-LIC-LOCATION:Europe/Brussels 
BEGIN:STANDARD 
TZOFFSETFROM:+0200 
TZOFFSETTO:+0100  
TZNAME:CET 
DTSTART:19701025T030000 
RRULE:FREQ=YEARLY;BYMONTH=10;BYDAY=-1SU 
END:STANDARD
BEGIN:DAYLIGHT
TZOFFSETFROM:+0100 
TZOFFSETTO:+0200 
TZNAME:CEST
DTSTART:19700329T020000 
RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=-1SU 
END:DAYLIGHT
END:VTIMEZONE 
END:VCALENDAR

In Component/VTimeZone I have found this comment:

// At least 1 STANDARD or DAYLIGHT must appear, or more. But both // cannot appear in the same VTIMEZONE.

Is there another way to add DAYLIGHT and STANDARD to a timezone. And why should both not appear in the same VTIMEZONE?

The rfc states that they are OPTIONAL and MAY occur more than once. rfc-5545

Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

roelmonnens avatar Apr 26 '16 10:04 roelmonnens

Hi!

I updated the docblock, you were correct that they can both appear in a vtimezone.

As for your other problem, I realized that there's something missing in sabre/vobject that prevents you from easily setting this up. You are currently treating the BEGIN:STANDARD and END:STANDARD as properties with the names BEGIN and END, but this is wrong.

Normally you should just be able to call:

$vtimezone->add('STANDARD', [
   'TZOFFSETFROM' => '+0200',
   /*** etc **/ 
]);

But something is missing to make this work! Workaround until I've fixed this:

$standard = $vtimezone->createComponent('STANDARD', [
   'TZOFFSETFROM' => '+0200',
   /*** etc **/ 
]);

$vtimezone->add($standard);

Here we explicitly tell vobject to create a component with name STANDARD and pass one or more properties.

After that it's still needed to call add on $vtimezone, because we only created the component, but didn't insert it anywhere in the document.

evert avatar Apr 26 '16 13:04 evert

Thnx Workaround works fine!

roelmonnens avatar Apr 27 '16 10:04 roelmonnens

Maybe this issue should be mentioned on the documentation at http://sabre.io/vobject/usage_2/, Date and time handling section. Aside of the coexistence issue with DAYLIGHT and TIMEZONE, we currently cannot declare a TIMEZONE block the way it's supposed to be (without $vtimezone->add('BEGIN', ... )).

saulojg avatar Aug 15 '16 00:08 saulojg