PluginProbe
Booking Manager – Sync WP Booking Calendar – Import Events, Export Bookings to ICS Calendar / 2.0
Booking Manager – Sync WP Booking Calendar – Import Events, Export Bookings to ICS Calendar v2.0
2.1.21 2.1.20 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 trunk 1.1 2.0 2.0.1 2.0.10.2 2.0.11 2.0.12 2.0.13 2.0.14 2.0.15 2.0.16 2.0.17 2.0.18 2.0.2 2.0.20 2.0.21 2.0.22 All 55 releases
booking-manager / assets / libs / icalendar / includes / timezone.php

timezone.php in Booking Manager – Sync WP Booking Calendar – Import Events, Export Bookings to ICS Calendar 2.0, at assets/libs/icalendar/includes/timezone.php

137 lines 3.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Zap Calendar Time Zone Helper Class
5 *
6 * @copyright Copyright (C) 2006 - 2016 by Dan Cogliano
7 * @license GNU General Public License version 2 or later; see LICENSE.txt
8 */
9
10 // No direct access
11 defined('_ZAPCAL') or die( 'Restricted access' );
12
13 /**
14 * Class to help create timezone section of iCalendar file
15 *
16 */
17 class ZCTimeZoneHelper {
18
19 /**
20 * getTZNode creates VTIMEZONE section in an iCalendar file
21 *
22 * @param @startyear int start year of date range
23 *
24 * @param @endyear int end year of date range
25 *
26 * @param $tzid string PHP timezone, use underscore for multiple words (i.e. "New_York" for "New York")
27 *
28 * @param $parentnode object iCalendar object where VTIMEZONE will be created
29 *
30 * @return object return VTIMEZONE object
31 */
32 static function getTZNode($startyear, $endyear, $tzid, $parentnode)
33 {
34 $tzmins = array();
35 $tzmaxs = array();
36 if(!array_key_exists($tzid,$tzmins) || $tzmins[$tzid] > $startyear)
37 {
38 $tzmins[$tzid] = $startyear;
39 }
40 if(!array_key_exists($tzid,$tzmaxs) || $tzmaxs[$tzid] < $endyear)
41 {
42 $tzmaxs[$tzid] = $endyear;
43 }
44
45 foreach(array_keys($tzmins) as $tzid)
46 {
47 $tmin = $tzmins[$tzid] - 1;
48 if(array_key_exists($tzid,$tzmaxs))
49 {
50 $tmax = $tzmaxs[$tzid] + 1;
51 }
52 else
53 {
54 $tmax = $tzmins[$tzid] + 1;
55 }
56 $tstart = gmmktime(0,0,0,1,1,$tmin);
57 $tend = gmmktime(23,59,59,12,31,$tmax);
58 $tz = new DateTimeZone($tzid);
59 $transitions = $tz->getTransitions($tstart,$tend);
60 $tzobj = new ZCiCalNode("VTIMEZONE", $parentnode, true);
61 $datanode = new ZCiCalDataNode("TZID:" . str_replace("_"," ",$tzid));
62 $tzobj->data[$datanode->getName()] = $datanode;
63 $count = 0;
64 $lasttransition = null;
65 if(count($transitions) == 1)
66 {
67 // not enough transitions found, probably UTC
68 // lets add fake transition at end for those systems that need it (i.e. Outlook)
69
70 $t2 = array();
71 $t2["isdst"] = $transitions[0]["isdst"];
72 $t2["offset"] = $transitions[0]["offset"];
73 $t2["ts"] = $tstart;
74 $t2["abbr"] = $transitions[0]["abbr"];
75 $transitions[] = $t2;
76 }
77 foreach($transitions as $transition)
78 {
79 $count++;
80 if($count == 1)
81 {
82 $lasttransition = $transition;
83 continue; // skip first item
84 }
85 if($transition["isdst"] == 1)
86 {
87 $tobj = new ZCiCalNode("DAYLIGHT", $tzobj);
88 }
89 else
90 {
91 $tobj = new ZCiCalNode("STANDARD", $tzobj);
92 }
93 //$tzobj->data[$tobj->getName()] == $tobj;
94
95 // convert timestamp to local time zone
96 $ts = ZDateHelper::toUnixDateTime(ZDateHelper::toLocalDateTime(ZDateHelper::toSQLDateTime($transition["ts"]),$tzid));
97 $datanode = new ZCiCalDataNode("DTSTART:".ZDateHelper::toICalDateTime($ts));
98 $tobj->data[$datanode->getName()] = $datanode;
99 //echo $ts . " => " . ZDateHelper::toICalDateTime($ts) . "<br/>\n"; exit;
100 $toffset = $lasttransition["offset"];
101 $thours = intval($toffset/60/60);
102 $tmins = abs($toffset)/60 - intval(abs($toffset)/60/60)*60;
103 if($thours < 0)
104 {
105 $offset = sprintf("%03d%02d",$thours,$tmins);
106 }
107 else
108 {
109 $offset = sprintf("+%02d%02d",$thours,$tmins);
110 }
111 $datanode = new ZCiCalDataNode("TZOFFSETFROM:".$offset);
112 $tobj->data[$datanode->getName()] = $datanode;
113
114 $toffset = $transition["offset"];
115 $thours = intval($toffset/60/60);
116 $tmins = abs($toffset)/60 - intval(abs($toffset)/60/60)*60;
117 if($thours < 0)
118 {
119 $offset = sprintf("%03d%02d",$thours,$tmins);
120 }
121 else
122 {
123 $offset = sprintf("+%02d%02d",$thours,$tmins);
124 }
125 $datanode = new ZCiCalDataNode("TZOFFSETTO:".$offset);
126 $tobj->data[$datanode->getName()] = $datanode;
127
128 $datanode = new ZCiCalDataNode("TZNAME:".$transition["abbr"]);
129 $tobj->data[$datanode->getName()] = $datanode;
130
131 $lasttransition = $transition;
132 }
133 }
134 return $tzobj;
135 }
136 }
137