roundcubemail-plugins-kolab/plugins/libkolab/bin/Date_last_weekday.diff

37 lines
1.2 KiB
Diff

--- Date.php.orig 2012-07-10 19:14:26.000000000 +0200
+++ Date.php 2012-07-10 19:16:22.000000000 +0200
@@ -627,16 +627,25 @@
return;
}
- $this->_mday = 1;
- $first = $this->dayOfWeek();
- if ($weekday < $first) {
- $this->_mday = 8 + $weekday - $first;
- } else {
- $this->_mday = $weekday - $first + 1;
+ if ($nth < 0) { // last $weekday of month
+ $this->_mday = $lastday = Horde_Date_Utils::daysInMonth($this->_month, $this->_year);
+ $last = $this->dayOfWeek();
+ $this->_mday += ($weekday - $last);
+ if ($this->_mday > $lastday)
+ $this->_mday -= 7;
+ }
+ else {
+ $this->_mday = 1;
+ $first = $this->dayOfWeek();
+ if ($weekday < $first) {
+ $this->_mday = 8 + $weekday - $first;
+ } else {
+ $this->_mday = $weekday - $first + 1;
+ }
+ $diff = 7 * $nth - 7;
+ $this->_mday += $diff;
+ $this->_correct(self::MASK_DAY, $diff < 0);
}
- $diff = 7 * $nth - 7;
- $this->_mday += $diff;
- $this->_correct(self::MASK_DAY, $diff < 0);
}
/**