);
public $dayNameScanner = array(
- '/^m[ou]n(day)?$/' => Horde_Date::DATE_MONDAY,
- '/^t(ue|eu|oo|u|)s(day)?$/' => Horde_Date::DATE_TUESDAY,
- '/^tue$/' => Horde_Date::DATE_TUESDAY,
- '/^we(dnes|nds|nns)day$/' => Horde_Date::DATE_WEDNESDAY,
- '/^wed$/' => Horde_Date::DATE_WEDNESDAY,
- '/^th(urs|ers)day$/' => Horde_Date::DATE_THURSDAY,
- '/^thu$/' => Horde_Date::DATE_THURSDAY,
- '/^fr[iy](day)?$/' => Horde_Date::DATE_FRIDAY,
- '/^sat(t?[ue]rday)?$/' => Horde_Date::DATE_SATURDAY,
- '/^su[nm](day)?$/' => Horde_Date::DATE_SUNDAY,
+ '/^m[ou]n(day)?$/' => 'monday',
+ '/^t(ue|eu|oo|u|)s(day)?$/' => 'tuesday',
+ '/^tue$/' => 'tuesday',
+ '/^we(dnes|nds|nns)day$/' => 'wednesday',
+ '/^wed$/' => 'wednesday',
+ '/^th(urs|ers)day$/' => 'thursday',
+ '/^thu$/' => 'thursday',
+ '/^fr[iy](day)?$/' => 'friday',
+ '/^sat(t?[ue]rday)?$/' => 'saturday',
+ '/^su[nm](day)?$/' => 'sunday',
);
public $dayPortionScanner = array(
*/
abstract class Horde_Date_Repeater
{
+ public $now;
+
/**
* returns the width (in seconds or months) of this repeatable.
*/
const DAY_SECONDS = 86400;
public $currentDayStart;
+ public $type;
+
+ public function __construct($type)
+ {
+ $this->type = $type;
+ }
public function next($pointer)
{
if (!$this->currentDayStart) {
$this->currentDayStart = new Horde_Date(array('year' => $this->now->year, 'month' => $this->now->month, 'day' => $this->now->day + $direction));
- $dayNum = $this->type;
+ $dayNum = $this->_dayNumber($this->type);
while ($this->currentDayStart->dayOfWeek() != $dayNum) {
$this->currentDayStart->day += $direction;
}
public function __toString()
{
- $dayStrings = array(
- Horde_Date::DATE_MONDAY => 'monday',
- Horde_Date::DATE_TUESDAY => 'tuesday',
- Horde_Date::DATE_WEDNESDAY => 'wednesday',
- Horde_Date::DATE_THURSDAY => 'thursday',
- Horde_Date::DATE_FRIDAY => 'friday',
- Horde_Date::DATE_SATURDAY => 'saturday',
- Horde_Date::DATE_SUNDAY => 'sunday',
+ return parent::__toString() . '-dayname-' . $this->type;
+ }
+
+ protected function _dayNumber($dayName)
+ {
+ $days = array(
+ 'monday' => Horde_Date::DATE_MONDAY,
+ 'tuesday' => Horde_Date::DATE_TUESDAY,
+ 'wednesday' => Horde_Date::DATE_WEDNESDAY,
+ 'thursday' => Horde_Date::DATE_THURSDAY,
+ 'friday' => Horde_Date::DATE_FRIDAY,
+ 'saturday' => Horde_Date::DATE_SATURDAY,
+ 'sunday' => Horde_Date::DATE_SUNDAY,
);
- return parent::__toString() . '-dayname-' . $dayStrings[$this->type];
+ if (!isset($days[$dayName])) {
+ throw new InvalidArgumentException('Invalid day name "' . $dayName . '"');
+ }
+ return $days[$dayName];
}
}
public $range;
public $currentSpan;
+ public $type;
public function __construct($type)
{
- parent::__construct($type);
+ $this->type = $type;
if (is_int($type)) {
$this->range = array(($type * 3600), (($type + 12) * 3600));
class Horde_Date_Repeater_MonthName extends Horde_Date_Repeater
{
public $currentMonthStart;
+ public $type;
+
+ public function __construct($type)
+ {
+ $this->type = $type;
+ }
public function next($pointer)
{
public $autumn = array('sep 23', 'dec 21');
public $winter = array('dec 22', 'mar 19');
public $spring = array('mar 20', 'jul 20');
+ public $type;
+
+ public function __construct($type)
+ {
+ $this->type = $type;
+ }
public function next($pointer)
{
class Horde_Date_Repeater_Time extends Horde_Date_Repeater
{
public $currentTime;
+ public $type;
public function __construct($time, $options = array())
{
*/
public function add($factor)
{
- $b = clone($this->begin);
- $e = clone($this->end);
- if (is_array($factor)) {
- foreach ($factor as $property => $value) {
- $b->$property += $value;
- $e->$property += $value;
- }
- } else {
- $b->sec += $factor;
- $e->sec += $factor;
- }
- return new Horde_Date_Span($b, $e);
+ return new Horde_Date_Span($this->begin->add($factor), $this->end->add($factor));
}
/**
*/
public function sub($factor)
{
- if (is_array($factor)) {
- foreach ($factor as &$value) {
- $value *= -1;
- }
- } else {
- $factor *= -1;
- }
-
- return $this->add($factor);
+ return new Horde_Date_Span($this->begin->sub($factor), $this->end->sub($factor));
}
public function __toString()