Branch 'roundcubemail-plugins-kolab-0.7' - 2 commits - plugins/calendar
Thomas Brüderli
bruederli at kolabsys.com
Fri Nov 2 16:26:00 CET 2012
plugins/calendar/calendar.php | 41 ++++++++++++++++++++--
plugins/calendar/drivers/kolab/kolab_calendar.php | 4 +-
plugins/calendar/drivers/kolab/kolab_driver.php | 5 +-
plugins/calendar/lib/Horde_Date_Recurrence.php | 5 ++
plugins/calendar/lib/calendar_recurrence.php | 12 +-----
5 files changed, 51 insertions(+), 16 deletions(-)
New commits:
commit 728a28c5e9c5cafd639a5357d2bf40280a35633f
Author: Thomas Bruederli <bruederli at kolabsys.com>
Date: Fri Nov 2 16:25:25 2012 +0100
Fix recurrence computation with UMTIL date
diff --git a/plugins/calendar/drivers/kolab/kolab_calendar.php b/plugins/calendar/drivers/kolab/kolab_calendar.php
index b7a1bc8..84f7dca 100644
--- a/plugins/calendar/drivers/kolab/kolab_calendar.php
+++ b/plugins/calendar/drivers/kolab/kolab_calendar.php
@@ -532,8 +532,8 @@ class kolab_calendar
if ($recurrence['range-type'] == 'number')
$rrule['COUNT'] = intval($recurrence['range']);
else if ($recurrence['range-type'] == 'date') {
- $rrule['UNTIL'] = new DateTime('@'.$recurrence['range']);
- $rrule['UNTIL']->setTimezone($this->cal->user_timezone);
+ $rrule['UNTIL'] = new DateTime('@' . $recurrence['range']);
+ $rrule['UNTIL']->setTimezone(new DateTimeZone(date_default_timezone_get()));
}
if ($recurrence['day']) {
diff --git a/plugins/calendar/drivers/kolab/kolab_driver.php b/plugins/calendar/drivers/kolab/kolab_driver.php
index e470fe2..55b08a1 100644
--- a/plugins/calendar/drivers/kolab/kolab_driver.php
+++ b/plugins/calendar/drivers/kolab/kolab_driver.php
@@ -498,7 +498,7 @@ class kolab_driver extends calendar_driver
// removing the first instance => just move to next occurence
if ($master['id'] == $event['id']) {
- $recurring = reset($storage->_get_recurring_events($event, $event['start'], $event['end'] + 86400 * 370, $event['id'].'-1'));
+ $recurring = reset($storage->_get_recurring_events($event, $event['start']->format('U'), $event['end']->format('U') + 86400 * 370, $event['id'].'-1'));
$master['start'] = $recurring['start'];
$master['end'] = $recurring['end'];
if ($master['recurrence']['COUNT'])
@@ -515,7 +515,8 @@ class kolab_driver extends calendar_driver
$_SESSION['calendar_restore_event_data'] = $master;
// set until-date on master event
- $master['recurrence']['UNTIL'] = $event['start'] - 86400;
+ $master['recurrence']['UNTIL'] = clone $event['start'];
+ $master['recurrence']['UNTIL']->modify('-1 day');
unset($master['recurrence']['COUNT']);
$success = $storage->update_event($master);
break;
diff --git a/plugins/calendar/lib/Horde_Date_Recurrence.php b/plugins/calendar/lib/Horde_Date_Recurrence.php
index 68340ba..d6debf3 100644
--- a/plugins/calendar/lib/Horde_Date_Recurrence.php
+++ b/plugins/calendar/lib/Horde_Date_Recurrence.php
@@ -6307,7 +6307,10 @@ class Horde_Date_Recurrence {
'%04d%02d%02d');
$this->setRecurEnd(new Horde_Date(array('year' => $year,
'month' => $month,
- 'mday' => $mday)));
+ 'mday' => $mday,
+ 'hour' => 23,
+ 'min' => 59,
+ 'sec' => 59)));
}
if (isset($rdata['COUNT'])) {
$this->setRecurCount($rdata['COUNT']);
diff --git a/plugins/calendar/lib/calendar_recurrence.php b/plugins/calendar/lib/calendar_recurrence.php
index ce1738b..51a0fdd 100644
--- a/plugins/calendar/lib/calendar_recurrence.php
+++ b/plugins/calendar/lib/calendar_recurrence.php
@@ -53,14 +53,8 @@ class calendar_recurrence
// TODO: replace with something that has less than 6'000 lines of code
require_once($this->cal->home . '/lib/Horde_Date_Recurrence.php');
- // shift until date by one day in order to trick the Horde_Date_Recurrence computation
- if ($event['recurrence']['UNTIL']) {
- $event['recurrence']['UNTIL'] = clone $event['recurrence']['UNTIL'];
- $event['recurrence']['UNTIL']->modify('+1 day');
- }
-
$this->event = $event;
- $this->engine = new Horde_Date_Recurrence($dtstart->format('U'));
+ $this->engine = new Horde_Date_Recurrence($dtstart->format('Y-m-d H:i:s'));
$this->engine->fromRRule20(calendar::to_rrule($event['recurrence']));
if (is_array($event['recurrence']['EXDATE'])) {
@@ -69,7 +63,7 @@ class calendar_recurrence
}
$this->tz_offset = $event['allday'] ? $this->cal->gmt_offset - date('Z') : 0;
- $this->next = new Horde_Date($dtstart->format('U'));
+ $this->next = new Horde_Date($dtstart->format('Y-m-d H:i:s'));
$this->hour = $this->next->hour;
}
@@ -87,7 +81,7 @@ class calendar_recurrence
$next->hour = $this->hour;
$next->min = 0;
}
- $time = new DateTime($next->iso8601DateTime(), $this->cal->user_timezone);
+ $time = new DateTime($next->rfc3339DateTime(), $this->cal->user_timezone);
$this->next = $next;
}
commit 1d18e0a064d77b79c824e1f24bb6cc752ca07c80
Author: Thomas Bruederli <bruederli at kolabsys.com>
Date: Fri Nov 2 16:24:41 2012 +0100
Better timezone resolver
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;
+ }
+
}
More information about the commits
mailing list