}
/**
- * Returns whether a year is a leap year.
- *
- * @param integer $year The year.
- *
- * @return boolan True if the year is a leap year.
- */
- public static function isLeapYear($year)
- {
- if (strlen($year) != 4 || preg_match('/\D/', $year)) {
- return false;
- }
-
- return (($year % 4 == 0 && $year % 100 != 0) || $year % 400 == 0);
- }
-
- /**
- * Returns the date of the year that corresponds to the first day of the
- * given week.
- *
- * @param integer $week The week of the year to find the first day of.
- * @param integer $year The year to calculate for.
- *
- * @return Horde_Date The date of the first day of the given week.
- */
- public static function firstDayOfWeek($week, $year)
- {
- return new Horde_Date(sprintf('%04dW%02d', $year, $week));
- }
-
- /**
- * Returns the number of days in the specified month.
- *
- * @param integer $month The month
- * @param integer $year The year.
- *
- * @return integer The number of days in the month.
- */
- public static function daysInMonth($month, $year)
- {
- static $cache = array();
- if (!isset($cache[$year][$month])) {
- $date = new DateTime(sprintf('%04d-%02d-01', $year, $month));
- $cache[$year][$month] = $date->format('t');
- }
- return $cache[$year][$month];
- }
-
- /**
* Returns the day of the week (0 = Sunday, 6 = Saturday) of this date.
*
* @return integer The day of the week.
if ($mask & self::MASK_DAY) {
while ($this->_mday > 28 &&
- $this->_mday > Horde_Date::daysInMonth($this->_month, $this->_year)) {
- $this->_mday -= Horde_Date::daysInMonth($this->_month, $this->_year);
+ $this->_mday > Horde_Date_Utils::daysInMonth($this->_month, $this->_year)) {
+ $this->_mday -= Horde_Date_Utils::daysInMonth($this->_month, $this->_year);
++$this->_month;
$this->_correct(self::MASK_MONTH);
}
while ($this->_mday < 1) {
--$this->_month;
$this->_correct(self::MASK_MONTH);
- $this->_mday += Horde_Date::daysInMonth($this->_month, $this->_year);
+ $this->_mday += Horde_Date_Utils::daysInMonth($this->_month, $this->_year);
}
}
}
return false;
}
- $start_week = Horde_Date::firstDayOfWeek($this->start->format('W'),
- $this->start->year);
+ $start_week = Horde_Date_Utils::firstDayOfWeek($this->start->format('W'),
+ $this->start->year);
$start_week->hour = $this->start->hour;
$start_week->min = $this->start->min;
$start_week->sec = $this->start->sec;
} else {
$theYear = $after->year;
}
- $after_week = Horde_Date::firstDayOfWeek($week, $theYear);
+ $after_week = Horde_Date_Utils::firstDayOfWeek($week, $theYear);
$after_week_end = clone $after_week;
$after_week_end->mday += 7;
// Seperate case here for February 29th
if ($estart->month == 2 && $estart->mday == 29) {
- while (!Horde_Date::isLeapYear($after->year)) {
+ while (!Horde_Date_Utils::isLeapYear($after->year)) {
++$after->year;
}
}
case 'W':
$this->setRecurType(self::RECUR_WEEKLY);
if (!empty($remainder)) {
- $maskdays = array('SU' => Horde_Date::MASK_SUNDAY,
- 'MO' => Horde_Date::MASK_MONDAY,
- 'TU' => Horde_Date::MASK_TUESDAY,
- 'WE' => Horde_Date::MASK_WEDNESDAY,
- 'TH' => Horde_Date::MASK_THURSDAY,
- 'FR' => Horde_Date::MASK_FRIDAY,
- 'SA' => Horde_Date::MASK_SATURDAY);
+ $maskdays = array(
+ 'SU' => Horde_Date::MASK_SUNDAY,
+ 'MO' => Horde_Date::MASK_MONDAY,
+ 'TU' => Horde_Date::MASK_TUESDAY,
+ 'WE' => Horde_Date::MASK_WEDNESDAY,
+ 'TH' => Horde_Date::MASK_THURSDAY,
+ 'FR' => Horde_Date::MASK_FRIDAY,
+ 'SA' => Horde_Date::MASK_SATURDAY,
+ );
$mask = 0;
while (preg_match('/^ ?[A-Z]{2} ?/', $remainder, $matches)) {
$day = trim($matches[0]);
$this->setRecurOnDay($mask);
} else {
// Recur on the day of the week of the original recurrence.
- $maskdays = array(Horde_Date::DATE_SUNDAY => Horde_Date::MASK_SUNDAY,
- Horde_Date::DATE_MONDAY => Horde_Date::MASK_MONDAY,
- Horde_Date::DATE_TUESDAY => Horde_Date::MASK_TUESDAY,
- Horde_Date::DATE_WEDNESDAY => Horde_Date::MASK_WEDNESDAY,
- Horde_Date::DATE_THURSDAY => Horde_Date::MASK_THURSDAY,
- Horde_Date::DATE_FRIDAY => Horde_Date::MASK_FRIDAY,
- Horde_Date::DATE_SATURDAY => Horde_Date::MASK_SATURDAY);
+ $maskdays = array(
+ Horde_Date::DATE_SUNDAY => Horde_Date::MASK_SUNDAY,
+ Horde_Date::DATE_MONDAY => Horde_Date::MASK_MONDAY,
+ Horde_Date::DATE_TUESDAY => Horde_Date::MASK_TUESDAY,
+ Horde_Date::DATE_WEDNESDAY => Horde_Date::MASK_WEDNESDAY,
+ Horde_Date::DATE_THURSDAY => Horde_Date::MASK_THURSDAY,
+ Horde_Date::DATE_FRIDAY => Horde_Date::MASK_FRIDAY,
+ Horde_Date::DATE_SATURDAY => Horde_Date::MASK_SATURDAY,
+ );
$this->setRecurOnDay($maskdays[$this->start->dayOfWeek()]);
}
break;
case 'WEEKLY':
$this->setRecurType(self::RECUR_WEEKLY);
if (isset($rdata['BYDAY'])) {
- $maskdays = array('SU' => Horde_Date::MASK_SUNDAY,
- 'MO' => Horde_Date::MASK_MONDAY,
- 'TU' => Horde_Date::MASK_TUESDAY,
- 'WE' => Horde_Date::MASK_WEDNESDAY,
- 'TH' => Horde_Date::MASK_THURSDAY,
- 'FR' => Horde_Date::MASK_FRIDAY,
- 'SA' => Horde_Date::MASK_SATURDAY);
+ $maskdays = array(
+ 'SU' => Horde_Date::MASK_SUNDAY,
+ 'MO' => Horde_Date::MASK_MONDAY,
+ 'TU' => Horde_Date::MASK_TUESDAY,
+ 'WE' => Horde_Date::MASK_WEDNESDAY,
+ 'TH' => Horde_Date::MASK_THURSDAY,
+ 'FR' => Horde_Date::MASK_FRIDAY,
+ 'SA' => Horde_Date::MASK_SATURDAY,
+ );
$days = explode(',', $rdata['BYDAY']);
$mask = 0;
foreach ($days as $day) {
--- /dev/null
+<?php
+/**
+ * Horde Date wrapper/logic class, including some calculation
+ * functions.
+ *
+ * @category Horde
+ * @package Horde_Date
+ */
+
+
+/**
+ * @category Horde
+ * @package Horde_Date
+ */
+class Horde_Date_Utils
+{
+ /**
+ * Returns whether a year is a leap year.
+ *
+ * @param integer $year The year.
+ *
+ * @return boolean True if the year is a leap year.
+ */
+ public static function isLeapYear($year)
+ {
+ if (strlen($year) != 4 || preg_match('/\D/', $year)) {
+ return false;
+ }
+
+ return (($year % 4 == 0 && $year % 100 != 0) || $year % 400 == 0);
+ }
+
+ /**
+ * Returns the date of the year that corresponds to the first day of the
+ * given week.
+ *
+ * @param integer $week The week of the year to find the first day of.
+ * @param integer $year The year to calculate for.
+ *
+ * @return Horde_Date The date of the first day of the given week.
+ */
+ public static function firstDayOfWeek($week, $year)
+ {
+ return new Horde_Date(sprintf('%04dW%02d', $year, $week));
+ }
+
+ /**
+ * Returns the number of days in the specified month.
+ *
+ * @param integer $month The month
+ * @param integer $year The year.
+ *
+ * @return integer The number of days in the month.
+ */
+ public static function daysInMonth($month, $year)
+ {
+ static $cache = array();
+ if (!isset($cache[$year][$month])) {
+ $date = new DateTime(sprintf('%04d-%02d-01', $year, $month));
+ $cache[$year][$month] = $date->format('t');
+ }
+ return $cache[$year][$month];
+ }
+
+}
{
public function testFirstDayOfWeek()
{
- $this->assertEquals('2006-01-02', Horde_Date::firstDayOfWeek(1, 2006)->format('Y-m-d'));
- $this->assertEquals('2007-01-01', Horde_Date::firstDayOfWeek(1, 2007)->format('Y-m-d'));
- $this->assertEquals('2007-12-31', Horde_Date::firstDayOfWeek(1, 2008)->format('Y-m-d'));
- $this->assertEquals('2010-01-04', Horde_Date::firstDayOfWeek(1, 2010)->format('Y-m-d'));
+ $this->assertEquals('2006-01-02', Horde_Date_Utils::firstDayOfWeek(1, 2006)->format('Y-m-d'));
+ $this->assertEquals('2007-01-01', Horde_Date_Utils::firstDayOfWeek(1, 2007)->format('Y-m-d'));
+ $this->assertEquals('2007-12-31', Horde_Date_Utils::firstDayOfWeek(1, 2008)->format('Y-m-d'));
+ $this->assertEquals('2010-01-04', Horde_Date_Utils::firstDayOfWeek(1, 2010)->format('Y-m-d'));
}
}