u01jmg3 / ics-parser

Parser for iCalendar Events • PHP 8+, 7 (≥ 7.4), 5 (≥ 5.6)
MIT License
448 stars 144 forks source link

Timezone issue #244

Closed dico closed 4 years ago

dico commented 4 years ago

Description of the Issue:

Wrong timeformat when using both default ICS sharing from Google calendar and Office 365 Outlook.

Steps to Reproduce:

  1. Generate default ics url from Office 365 Outlook and Google Calendar.

Output from Google Calendar: Correct time should be 20:00 to 21:00

ICal\Event Object  
(  
    [summary] => Event 1  
    [dtstart] => 20191029T190000Z  
    [dtend] => 20191029T200000Z  
    ....  
    [dtstart_tz] => 20191029T200000  
    [dtend_tz] => 20191029T210000

Output from Office 365 Outlook: Correct time should be 09:30 to 15:00

ICal\Event Object  
(  
    [summary] => Event 2  
    [dtstart] => 20191030T093000  
    [dtend] => 20191030T150000  
    ....  
    [dtstart_tz] => 20191030T013000  
    [dtend_tz] => 20191030T070000

For the Google calendar, the dtstart_tz is correct, but for the Office 365 Outlook it's dtstart_tz.

In the .ics file, there are two VTIMEZONE for each file. Not sure why. Both clients are set correct in their settings (GUI), with only one option.

Google ICS

BEGIN:VTIMEZONE
TZID:Europe/Oslo
X-LIC-LOCATION:Europe/Oslo
BEGIN:DAYLIGHT
TZOFFSETFROM:+0100
TZOFFSETTO:+0200
TZNAME:CEST
DTSTART:19700329T020000
RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=-1SU
END:DAYLIGHT
BEGIN:STANDARD
TZOFFSETFROM:+0200
TZOFFSETTO:+0100
TZNAME:CET
DTSTART:19701025T030000
RRULE:FREQ=YEARLY;BYMONTH=10;BYDAY=-1SU
END:STANDARD
END:VTIMEZONE
BEGIN:VTIMEZONE
TZID:Europe/Amsterdam
X-LIC-LOCATION:Europe/Amsterdam
BEGIN:DAYLIGHT
TZOFFSETFROM:+0100
TZOFFSETTO:+0200
TZNAME:CEST
DTSTART:19700329T020000
RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=-1SU
END:DAYLIGHT
BEGIN:STANDARD
TZOFFSETFROM:+0200
TZOFFSETTO:+0100
TZNAME:CET
DTSTART:19701025T030000
RRULE:FREQ=YEARLY;BYMONTH=10;BYDAY=-1SU
END:STANDARD
END:VTIMEZONE

Office 365 Outlook ICS:

BEGIN:VTIMEZONE
TZID:W. Europe Standard Time
BEGIN:STANDARD
DTSTART:16010101T030000
TZOFFSETFROM:+0200
TZOFFSETTO:+0100
RRULE:FREQ=YEARLY;INTERVAL=1;BYDAY=-1SU;BYMONTH=10
END:STANDARD
BEGIN:DAYLIGHT
DTSTART:16010101T020000
TZOFFSETFROM:+0100
TZOFFSETTO:+0200
RRULE:FREQ=YEARLY;INTERVAL=1;BYDAY=-1SU;BYMONTH=3
END:DAYLIGHT
END:VTIMEZONE
BEGIN:VTIMEZONE
TZID:US/Pacific
BEGIN:STANDARD
DTSTART:16010101T020000
TZOFFSETFROM:-0700
TZOFFSETTO:-0800
RRULE:FREQ=YEARLY;INTERVAL=1;BYDAY=1SU;BYMONTH=11
END:STANDARD
BEGIN:DAYLIGHT
DTSTART:16010101T020000
TZOFFSETFROM:-0800
TZOFFSETTO:-0700
RRULE:FREQ=YEARLY;INTERVAL=1;BYDAY=2SU;BYMONTH=3
END:DAYLIGHT
END:VTIMEZONE

Suggested solution, use the first VTIMEZONE, as this looks to be primary timezone?

whcrg commented 4 years ago

For me also time zones are not working (calendar exported from google). Tried with firrefent versions of time zone declarations and also commenting out the 'defaultTimeZone' of the example but nothing seems to affect the result; the example code always gives events in GMT time.

Snapshot of the ics: https://uvkk.kirah.fi/rislointra/basic.ics

Google calendar and my android phone and mac where the same calendar is synced to give the right time for event (GMT+2 / Europe/Riga).

nekromoff commented 4 years ago

I can confirm this issue as well for Google. It must have started recently only, because I just found out about it.

E.g. Google calendar event start is 17:00, end 18:00, I get incorrectly 16:00 to 17:00 instead.

nekromoff commented 4 years ago

I have fixed this issue by using dtstart_tz instead of dtend_array[3] (and same for the end).

u01jmg3 commented 4 years ago

@dico, @whcrg: does the solution suggested by @nekromoff fix your issue?

u01jmg3 commented 4 years ago

Closing due to a lack of response