Skip to content

Commit

Permalink
[jan] Fix missing time of day in DTSTART and UNTIL properties.
Browse files Browse the repository at this point in the history
  • Loading branch information
yunosh committed Oct 18, 2013
1 parent f207d5d commit 24f13b8
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 15 deletions.
50 changes: 35 additions & 15 deletions framework/Timezone/lib/Horde/Timezone/Rule.php
Expand Up @@ -111,11 +111,14 @@ public function addRules(Horde_Icalendar_Vtimezone $tz, $tzid, $name,
$component->setAttribute('TZOFFSETTO', $offset);
}
$month = Horde_Timezone::getMonth($rule[5]);
// Retrieve time of rule start.
preg_match('/(\d+)(?::(\d+))?(?::(\d+))?(w|s|u)?/', $rule[7], $match);
if (!isset($match[2])) {
$match[2] = 0;
}
if ($rule[2] == $rule[3] && preg_match('/^\d+$/', $rule[6])) {
if (!isset($match[2])) {
$match[2] = 0;
}
// Rule lasts only for a single year and starts on a specific
// date.
$rdate = new Horde_Date(
array('year' => $rule[2],
'month' => Horde_Timezone::getMonth($rule[5]),
Expand All @@ -125,11 +128,16 @@ public function addRules(Horde_Icalendar_Vtimezone $tz, $tzid, $name,
'sec' => 0));
$component->setAttribute('DTSTART', $rdate);
} elseif (substr($rule[6], 0, 4) == 'last') {
// Rule starts on the last of a certain weekday of the month.
$weekday = $this->_weekdays[substr($rule[6], 4, 3)];
$last = new Horde_Date(
$rule[2],
$month,
Horde_Date_Utils::daysInMonth($month, $rule[2]));
$last = new Horde_Date(array(
'year' => $rule[2],
'month' => $month,
'mday' => Horde_Date_Utils::daysInMonth($month, $rule[2]),
'hour' => $match[1],
'min' => $match[2],
'sec' => 0
));
while ($last->dayOfWeek() != $weekday) {
$last->mday--;
}
Expand Down Expand Up @@ -157,12 +165,18 @@ public function addRules(Horde_Icalendar_Vtimezone $tz, $tzid, $name,
. Horde_String::upper(substr($rule[6], 4, 2))
. ';BYMONTH=' . $month . $until);
} elseif (strpos($rule[6], '>=')) {
// Rule starts on a certain weekday after a certain day of
// month.
list($weekday, $day) = explode('>=', $rule[6]);
$weekdayInt = $this->_weekdays[substr($weekday, 0, 3)];
$first = new Horde_Date(
array('year' => $rule[2],
'month' => $month,
'mday' => $day));
$first = new Horde_Date(array(
'year' => $rule[2],
'month' => $month,
'mday' => $day,
'hour' => $match[1],
'min' => $match[2],
'sec' => 0
));
while ($first->dayOfWeek() != $weekdayInt) {
$first->mday++;
}
Expand Down Expand Up @@ -196,12 +210,18 @@ public function addRules(Horde_Icalendar_Vtimezone $tz, $tzid, $name,
. ';BYDAY=1' . Horde_String::upper(substr($weekday, 0, 2))
. $until);
} elseif (strpos($rule[6], '<=')) {
// Rule starts on a certain weekday before a certain day of
// month.
list($weekday, $day) = explode('>=', $rule[6]);
$weekdayInt = $this->_weekdays[substr($weekday, 0, 3)];
$last = new Horde_Date(
array('year' => $rule[2],
'month' => $month,
'mday' => $day));
$last = new Horde_Date(array(
'year' => $rule[2],
'month' => $month,
'mday' => $day,
'hour' => $match[1],
'min' => $match[2],
'sec' => 0
));
while ($last->dayOfWeek() != $weekdayInt) {
$last->mday--;
}
Expand Down
2 changes: 2 additions & 0 deletions framework/Timezone/package.xml
Expand Up @@ -22,6 +22,7 @@
</stability>
<license uri="http://www.horde.org/licenses/lgpl21">LGPL-2.1</license>
<notes>
* [jan] Fix missing time of day in DTSTART and UNTIL properties.
* [jan] Don&apos;t create transitions that overlap.
* [jan] Use orginally requested time zone instead of alias in TZID.
</notes>
Expand Down Expand Up @@ -197,6 +198,7 @@
<date>2013-05-06</date>
<license uri="http://www.horde.org/licenses/lgpl21">LGPL-2.1</license>
<notes>
* [jan] Fix missing time of day in DTSTART and UNTIL properties.
* [jan] Don&apos;t create transitions that overlap.
* [jan] Use orginally requested time zone instead of alias in TZID.
</notes>
Expand Down

0 comments on commit 24f13b8

Please sign in to comment.