aboutsummaryrefslogtreecommitdiffstats
path: root/functions
diff options
context:
space:
mode:
authorJim Hu <jimhu@users.sourceforge.net>2007-10-12 08:04:51 +0000
committerJim Hu <jimhu@users.sourceforge.net>2007-10-12 08:04:51 +0000
commiteb2fc16beac0d30d388d4f06718061422499d1b9 (patch)
tree507f1a6d5be22c9c29c6dc59eaaf96ed461cf26d /functions
parent2df4299569c667bf436ae35417d9f2a571959242 (diff)
downloadphpicalendar-eb2fc16beac0d30d388d4f06718061422499d1b9.tar.gz
phpicalendar-eb2fc16beac0d30d388d4f06718061422499d1b9.tar.bz2
phpicalendar-eb2fc16beac0d30d388d4f06718061422499d1b9.zip
add timezone parser
Diffstat (limited to 'functions')
-rw-r--r--functions/parse_tzs.php64
1 files changed, 64 insertions, 0 deletions
diff --git a/functions/parse_tzs.php b/functions/parse_tzs.php
new file mode 100644
index 0000000..85ab929
--- /dev/null
+++ b/functions/parse_tzs.php
@@ -0,0 +1,64 @@
+<?php
+$ifile = @fopen($filename, "r");
+if ($ifile == FALSE) exit(error($lang['l_error_cantopen'], $filename));
+$nextline = fgets($ifile, 1024);
+if (trim($nextline) != 'BEGIN:VCALENDAR') exit(error($lang['l_error_invalidcal'], $filename));
+
+// read file in line by line
+// XXX end line is skipped because of the 1-line readahead
+while (!feof($ifile)) {
+ $line = $nextline;
+ $nextline = fgets($ifile, 1024);
+ $nextline = ereg_replace("[\r\n]", "", $nextline);
+ #handle continuation lines that start with either a space or a tab (MS Outlook)
+ while (isset($nextline{0}) && ($nextline{0} == " " || $nextline{0} == "\t")) {
+ $line = $line . substr($nextline, 1);
+ $nextline = fgets($ifile, 1024);
+ $nextline = ereg_replace("[\r\n]", "", $nextline);
+ }
+ $line = trim($line);
+
+ switch ($line) {
+ case 'BEGIN:VTIMEZONE':
+ unset($tz_name, $offset_from, $offset_to, $tz_id);
+ break;
+ case 'BEGIN:STANDARD':
+ unset ($offset_s);
+ break;
+ case 'END:STANDARD':
+ $offset_s = $offset_to;
+ break;
+ case 'BEGIN:DAYLIGHT':
+ unset ($offset_d);
+ break;
+ case 'END:DAYLIGHT':
+ $offset_d = $offset_to;
+ break;
+ case 'END:VTIMEZONE':
+ $tz_array[$tz_id] = array($offset_s, $offset_d); #echo "<pre>$tz_id"; print_r($tz_array[$tz_id]);echo"</pre>";
+ break;
+ default:
+ unset ( $data, $prop_pos, $property);
+ if (ereg ("([^:]+):(.*)", $line, $line)){
+ $property = $line[1];
+ $data = $line[2];
+ $prop_pos = strpos($property,';');
+ if ($prop_pos !== false) $property = substr($property,0,$prop_pos);
+ $property = strtoupper($property);
+
+ switch ($property) {
+ case 'TZID':
+ $tz_id = $data;
+ break;
+ case 'TZOFFSETFROM':
+ $offset_from = $data;
+ break;
+ case 'TZOFFSETTO':
+ $offset_to = $data;
+ break;
+ }
+ }
+ }
+}
+
+?> \ No newline at end of file

© 2014-2024 Faster IT GmbH | imprint | privacy policy