Skip to content

Commit

Permalink
Closes #116 - correctly validate timezone
Browse files Browse the repository at this point in the history
  • Loading branch information
u01jmg3 committed Mar 29, 2017
1 parent 1cafc4c commit 668ea04
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/ICal/ICal.php
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ public function iCalDateToUnixTimestamp($icalDate)
if ($date[8] !== 'Z') {
if (isset($eventTimeZone) && $this->isValidTimeZoneId($eventTimeZone)) {
$timeZone = new \DateTimeZone($eventTimeZone);
} else if ($this->isValidTimeZoneId($eventTimeZone)) {
} else {
$timeZone = new \DateTimeZone($this->calendarTimeZone());
}
}
Expand Down Expand Up @@ -596,7 +596,7 @@ public function iCalDateWithTimeZone(array $event, $key, $forceTimeZone = false)
if (isset($dateArray[0]['TZID']) && preg_match('/[a-z]*\/[a-z_]*/i', $dateArray[0]['TZID'])) {
$timeZone = $dateArray[0]['TZID'];

if ($this->isValidTimeZoneId($timeZone)) {
if (!$this->isValidTimeZoneId($timeZone)) {
return $dateTime->format(self::DATE_TIME_FORMAT);
}
}
Expand Down

1 comment on commit 668ea04

@koernchen02
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@u01jmg3 First of all, thanks a lot for your work with this Package!
But I have a question...is it possible, that this wasn't cherry-picked into the v2.0.6 release ?
My composer states that I have installed

composer info johngrogg/ics-parser
name     : johngrogg/ics-parser
descrip. : ICS Parser
keywords : iCalendar, ical, ical-parser, ics, ics-parser, ifb
versions : * v2.0.6
type     : library
license  : MIT License (MIT) (OSI approved) https://spdx.org/licenses/MIT.html#licenseText
source   : [git] https://github.com/u01jmg3/ics-parser.git 2c9882b6d9408d1adaa7015f8ac88da2d42e2802
dist     : [zip] https://api.github.com/repos/u01jmg3/ics-parser/zipball/2c9882b6d9408d1adaa7015f8ac88da2d42e2802 2c9882b6d9408d1adaa7015f8ac88da2d42e2802
names    : johngrogg/ics-parser

autoload
psr-0
ICal => src/

requires
php >=5.3.0

requires (dev)
squizlabs/php_codesniffer ^2.5

But nonetheless, the iCalDateWithTimeZone method looks like that in my iCal Class:

    /**
     * Returns a date adapted to the calendar time zone depending on the event `TZID`
     *
     * @param  array  $event  An event
     * @param  string $key    An event property (`DTSTART` or `DTEND`)
     * @param  string $format The date format to apply
     * @return string|boolean
     */
    public function iCalDateWithTimeZone(array $event, $key, $format = self::DATE_TIME_FORMAT)
    {
        if (!isset($event[$key . '_array']) || !isset($event[$key])) {
            return false;
        }

        $dateArray = $event[$key . '_array'];
        $date      = $event[$key];

        if ($key === 'DURATION') {
            $duration = end($dateArray);
            $dateTime = $this->parseDuration($event['DTSTART'], $duration, null);
        } else {
            $dateTime = $this->iCalDateToDateTime($dateArray[3], false, true);
        }

        // Force time zone
        if (isset($dateArray[0]['TZID'])) {
            $dateTime->setTimezone(new \DateTimeZone($dateArray[0]['TZID']));
        }

        if (is_null($format)) {
            $output = $dateTime;
        } else {
            if ($format === self::UNIX_FORMAT) {
                $output = $dateTime->getTimestamp();
            } else {
                $output = $dateTime->format($format);
            }
        }

        return $output;
    }

Which leads to #116 not beeing closed for me, since my
ICS-files contain a nonsensical TZID W. Europe Standard Time:

BEGIN:VCALENDAR
PRODID:-//Alt-N Technologies Ltd//MDaemon 17.0.2
VERSION:2.0
METHOD:PUBLISH
BEGIN:VTIMEZONE
TZID:W. Europe Standard Time
BEGIN:STANDARD
DTSTART:16011005T030000
TZOFFSETFROM:+0200
TZOFFSETTO:+0100
RRULE:FREQ=YEARLY;BYDAY=-1SU;BYMONTH=10
TZNAME:Standard Time
END:STANDARD
BEGIN:DAYLIGHT
DTSTART:16010305T020000
TZOFFSETFROM:+0100
TZOFFSETTO:+0200
RRULE:FREQ=YEARLY;BYDAY=-1SU;BYMONTH=3
TZNAME:Daylight Savings Time
END:DAYLIGHT
END:VTIMEZONE
BEGIN:VEVENT
UID:040000008200E00074C5B7101A82E00800000000D00370ADE5C7CD01000000000000000010000000B9DB2CF9A11CC24A9568C7168A0775B2
SEQUENCE:0
DTSTAMP:20161019T085731Z
SUMMARY:What's the Matter with Norms? | Christoph Möllers | Dienstagskolloquium | Tuesday Colloquium
LOCATION:Großer Kolloquienraum (rp_gkr@mydomain.com)
ORGANIZER:MAILTO:psa@mydomain.com
PRIORITY:5
ATTENDEE;CN=Fellows_Events (kal_f-act@mydomain.com);CUTYPE=INDIVIDUAL;PARTSTAT=NEEDS-ACTION;ROLE=OPT-PARTICIPANT:MAILTO:kal_f-act@mydomain.com
ATTENDEE;CN=Fellows_www (kal_f-www@mydomain.com);CUTYPE=INDIVIDUAL;PARTSTAT=NEEDS-ACTION;ROLE=OPT-PARTICIPANT:MAILTO:kal_f-www@mydomain.com
DTSTART;TZID=W. Europe Standard Time:20121009T110000
DTEND;TZID=W. Europe Standard Time:20121009T130000
TRANSP:OPAQUE
X-MICROSOFT-DISALLOW-COUNTER:TRUE
END:VEVENT
END:VCALENDAR

I assume the error is on my end, but I would be really glad if you could help me out a little.
Best Regards and again, thanks a lot for your work!
Christian

Please sign in to comment.