From 7ff28aac1489f0c8467725169205287ed5e0c502 Mon Sep 17 00:00:00 2001 From: Chuck Hagenbuch Date: Tue, 3 Feb 2009 00:55:36 -0500 Subject: [PATCH] initial month repeater port --- .../Date/Parser/Locale/Base/Repeater/Month.php | 123 +++++++++++---------- 1 file changed, 63 insertions(+), 60 deletions(-) diff --git a/framework/Date_Parser/lib/Horde/Date/Parser/Locale/Base/Repeater/Month.php b/framework/Date_Parser/lib/Horde/Date/Parser/Locale/Base/Repeater/Month.php index bb3b1b403..6e6ca92cf 100644 --- a/framework/Date_Parser/lib/Horde/Date/Parser/Locale/Base/Repeater/Month.php +++ b/framework/Date_Parser/lib/Horde/Date/Parser/Locale/Base/Repeater/Month.php @@ -1,63 +1,66 @@ YEAR_MONTHS - new_year += 1 - new_month -= YEAR_MONTHS - end - Time.construct(new_year, new_month, time.day, time.hour, time.min, time.sec) - end - - def width - MONTH_SECONDS - end - - def to_s - super << '-month' - end -end \ No newline at end of file + /** + * 30 * 24 * 60 * 60 + */ + const MONTH_SECONDS = 2592000; + + public $currentMonthStart; + + public function next($pointer) + { + parent::next($pointer); + + if (!$this->currentMonthStart) { + $this->currentMonthStart = new Horde_Date(array('year' => $this->now->year, 'month' => $this->now->month)); + } + $direction = ($pointer == 'future') ? 1 : -1; + $this->currentMonthStart->month += $direction; + + $end = clone($this->currentMonthStart); + $end->month++; + return new Horde_Date_Span($this->currentMonthStart, $end); + } + + public function this($pointer = 'future') + { + parent::this($pointer); + + switch ($pointer) { + case 'future': + $monthStart = new Horde_Date(array('year' => $this->now->year, 'month' => $this->now->month, 'day' => $this->now->day + 1)); + $monthEnd = new Horde_Date(array('year' => $this->now->year, 'month' => $this->now->month + 1)); + break; + + case 'past': + $monthStart = new Horde_Date(array('year' => $this->now->year, 'month' => $this->now->month)); + $monthEnd = new Horde_Date(array('year' => $this->now->year, 'month' => $this->now->month, 'day' => $this->now->day)); + break; + + case 'none': + $monthStart = new Horde_Date(array('year' => $this->now->year, 'month' => $this->now->month)); + $monthEnd = new Horde_Date(array('year' => $this->now->year, 'month' => $this->now->month + 1)); + break; + } + + return new Horde_Date_Span($monthStart, $monthEnd); + } + + public function offset($span, $amount, $pointer) + { + $direction = ($pointer == 'future') ? 1 : -1; + return $span->add(array('month' => $amount * $direction)); + } + + public function width() + { + return self::MONTH_SECONDS; + } + + public function __toString() + { + return parent::__toString() . '-month'; + } + +} -- 2.11.0