summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Bruederli <bruederli@kolabsys.com>2012-11-02 15:24:41 (GMT)
committerThomas Bruederli <bruederli@kolabsys.com>2012-11-02 15:24:41 (GMT)
commit1d18e0a064d77b79c824e1f24bb6cc752ca07c80 (patch)
tree821b707cd38e3180bdf998b4c153efcac11affed
parentbd3c520a18fa2b8dd3ba2071c6cb11df80769c35 (diff)
downloadroundcubemail-plugins-kolab-1d18e0a064d77b79c824e1f24bb6cc752ca07c80.tar.gz
Better timezone resolver
-rw-r--r--plugins/calendar/calendar.php41
1 files changed, 39 insertions, 2 deletions
diff --git a/plugins/calendar/calendar.php b/plugins/calendar/calendar.php
index ec1d995..676e3ca 100644
--- a/plugins/calendar/calendar.php
+++ b/plugins/calendar/calendar.php
@@ -108,7 +108,7 @@ class calendar extends rcube_plugin
$this->gmt_offset = ($this->timezone + $this->dst_active) * 3600;
try {
- $this->user_timezone = new DateTimeZone($this->timezone ? timezone_name_from_abbr("", $this->gmt_offset, $this->dst_active) : 'GMT');
+ $this->user_timezone = new DateTimeZone($this->timezone ? self::tzOffsetToName($this->timezone, $this->dst_active) : 'GMT');
}
catch (Exception $e) {
$this->timezone = 0;
@@ -1076,7 +1076,7 @@ class calendar extends rcube_plugin
if ($event['recurrence'])
$event['recurrence_text'] = $this->_recurrence_text($event['recurrence']);
if ($event['recurrence']['UNTIL'])
- $event['recurrence']['UNTIL'] = $this->toUserDateTime($event['recurrence']['UNTIL'])->format('c');
+ $event['recurrence']['UNTIL'] = $event['recurrence']['UNTIL']->format('c');
return array(
'_id' => $event['calendar'] . ':' . $event['id'], // unique identifier for fullcalendar
@@ -2356,5 +2356,42 @@ class calendar extends rcube_plugin
return $url;
}
+ /**
+ * Converts a timezone hourly offset to its timezone's name.
+ * from http://ch.php.net/manual/en/function.timezone-name-from-abbr.php
+ *
+ * @param float $offset The timezone's offset in hours.
+ * Lowest value: -12 (Pacific/Kwajalein)
+ * Highest value: 14 (Pacific/Kiritimati)
+ * @param bool $isDst Is the offset for the timezone when it's in daylight savings time?
+ * @return string The name of the timezone: 'Asia/Tokyo', 'Europe/Paris', ...
+ */
+ public static function tzOffsetToName($offset, $isDst = null)
+ {
+ if ($isDst === null)
+ $isDst = date('I');
+
+ $offset *= 3600;
+ $zone = timezone_name_from_abbr('', $offset, $isDst);
+
+ if ($zone === false) {
+ foreach (timezone_abbreviations_list() as $abbr) {
+ foreach ($abbr as $city) {
+ if ((bool)$city['dst'] === (bool)$isDst &&
+ strlen($city['timezone_id']) > 0 &&
+ $city['offset'] == $offset) {
+ $zone = $city['timezone_id'];
+ break;
+ }
+ }
+
+ if ($zone !== false)
+ break;
+ }
+ }
+
+ return $zone;
+ }
+
}