PHP calendar parser that supports time zones

I am looking for a PHP class that can parse an ICalendar file (ICS) and handle time zones correctly.

I have already created the ICS parser, but it can only process time zones known to PHP (for example, "Europe / Paris").

Unfortunately, the ICS file created by Evolution (the default calendar software for Ubuntu) does not use default time zone identifiers. It exports events with its specific time zone identifier, which also exports the full definition of the time zone: daylight saving time dates, recurrence rule, and all the hard things to understand about time zones.

This is too much for me. Since this was just a small utility for my girlfriend, I will not have time to further study the ICalendar specification and create a full-scale ICalendar analyzer.

So, is there any known implementation in PHP of the ICalendar file format that can analyze the definitions of time intervals?

+6
timezone php parsing icalendar
source share
1 answer

Most likely, there are many libraries that parse .ics files, but I will show you one example that works well for me.

I used this library: http://www.phpclasses.org/browse/file/16660.html

This gives you great flexibility when working with various types of ICal components: VEVENT, VTODO, VJOURNAL, VFREEBUSY, VALARM and VTIMEZONE (the one you requested).

Example:

<pre><?php // // Open library // require_once( "iCalcreator.class.php" ) ; // // Demo ICal file contents // $string = <<<EOS BEGIN:VCALENDAR VERSION:2.0 PRODID:-//hacksw/handcal//NONSGML v1.0//EN BEGIN:VTIMEZONE TZID:US-Eastern LAST-MODIFIED:19870101T000000Z BEGIN:STANDARD DTSTART:19971026T020000 RDATE:19971026T020000 TZOFFSETFROM:-0400 TZOFFSETTO:-0500 TZNAME:EST END:STANDARD BEGIN:DAYLIGHT DTSTART:19971026T020000 RDATE:19970406T020000 TZOFFSETFROM:-0500 TZOFFSETTO:-0400 TZNAME:EDT END:DAYLIGHT END:VTIMEZONE END:VCALENDAR EOS ; // // There is no direct string parsing functionality, // so first create a temporary file // $filename = tempnam( ".", "" ) ; $f = fopen($filename,"w") ; fwrite( $f, $string ); fclose($f); // // ... parse it into an object // $var = new vcalendar(); $var->parse($filename); var_dump( $var ); $event = $var->components[0] ; var_dump( $event->createDtstamp() ); // // ... and finally remove all temporary data. // unlink($filename); 
+10
source share

All Articles