From aa443a84f429ec9954d986fddd1b1c3a293e6b02 Mon Sep 17 00:00:00 2001 From: Chuck Hagenbuch Date: Tue, 3 Feb 2009 11:37:26 -0500 Subject: [PATCH] initial monthname repeater port --- .../Date/Parser/Locale/Base/Repeater/MonthName.php | 110 +++++++++++---------- 1 file changed, 56 insertions(+), 54 deletions(-) diff --git a/framework/Date_Parser/lib/Horde/Date/Parser/Locale/Base/Repeater/MonthName.php b/framework/Date_Parser/lib/Horde/Date/Parser/Locale/Base/Repeater/MonthName.php index 8e3601e17..939f51dd8 100644 --- a/framework/Date_Parser/lib/Horde/Date/Parser/Locale/Base/Repeater/MonthName.php +++ b/framework/Date_Parser/lib/Horde/Date/Parser/Locale/Base/Repeater/MonthName.php @@ -14,51 +14,47 @@ class Horde_Date_Parser_Locale_Base_Repeater_MonthName extends Horde_Date_Parser if (!$this->currentMonthStart) { $targetMonth = $this->_monthNumber($this->type); - case pointer - when :future - if @now.month < target_month - @currentMonthStart = Time.construct(@now.year, target_month) - else @now.month > target_month - @currentMonthStart = Time.construct(@now.year + 1, target_month) - end - when :none - if @now.month <= target_month - @currentMonthStart = Time.construct(@now.year, target_month) - else @now.month > target_month - @currentMonthStart = Time.construct(@now.year + 1, target_month) - end - when :past - if @now.month > target_month - @currentMonthStart = Time.construct(@now.year, target_month) - else @now.month < target_month - @currentMonthStart = Time.construct(@now.year - 1, target_month) - end - end - @currentMonthStart || raise("Current month should be set by now") - else - case pointer - when :future - @currentMonthStart = Time.construct(@currentMonthStart.year + 1, @currentMonthStart.month) - when :past - @currentMonthStart = Time.construct(@currentMonthStart.year - 1, @currentMonthStart.month) - end - end + switch ($pointer) { + case 'future': + if ($this->now->month > $targetMonth) { + $this->currentMonthStart = new Horde_Date(array('year' => $this->now->year, 'month' => $targetMonth)); + } else { + $this->currentMonthStart = new Horde_Date(array('year' => $this->now->year + 1, 'month' => $targetMonth)); + } + break; - cur_month_year = @currentMonthStart.year - cur_month_month = @currentMonthStart.month + case 'none': + if ($this->now->month <= $targetMonth) { + $this->currentMonthStart = new Horde_Date(array('year' => $this->now->year, 'month' => $targetMonth)); + } else { + $this->currentMonthStart = new Horde_Date(array('year' => $this->now->year + 1, 'month' => $targetMonth)); + } + break; - if cur_month_month == 12 - next_month_year = cur_month_year + 1 - next_month_month = 1 - else - next_month_year = cur_month_year - next_month_month = cur_month_month + 1 - end + case 'past': + if ($this->now->month > $targetMonth) { + $this->currentMonthStart = new Horde_Date(array('year' => $this->now->year, 'month' => $targetMonth)); + } else { + $this->currentMonthStart = new Horde_Date(array('year' => $this->now->year - 1, 'month' => $targetMonth)); + } + break; + } + } else { + switch ($pointer) { + case 'future': + $this->currentMonthStart->year++; + break; - Chronic::Span.new(@currentMonthStart, Time.construct(next_month_year, next_month_month)) - end + case 'past': + $this->currentMonthStart->year--; + break; + } + } + + return new Horde_Date_Span($this->currentMonthStart, new Horde_Date(array('year' => $this->currentMonthStart->year, 'month' => $this->currentMonthStart->month + 1))); + } - public funcction this($pointer = 'future') + public function this($pointer = 'future') { parent::this($pointer); @@ -89,18 +85,24 @@ class Horde_Date_Parser_Locale_Base_Repeater_MonthName extends Horde_Date_Parser protected function _monthNumber($monthName) { - lookup = {:january => 1, - :february => 2, - :march => 3, - :april => 4, - :may => 5, - :june => 6, - :july => 7, - :august => 8, - :september => 9, - :october => 10, - :november => 11, - :december => 12} - lookup[sym] || raise("Invalid symbol specified") + $months = array( + 'january' => 1, + 'february' => 2, + 'march' => 3, + 'april' => 4, + 'may' => 5, + 'june' => 6, + 'july' => 7, + 'august' => 8, + 'september' => 9, + 'october' => 10, + 'november' => 11, + 'december' => 12, + ); + if (!isset($months[$monthName])) { + throw new InvalidArgumentException('Invalid month name "' . $monthName . '"'); + } + return $months[$monthName]; + } } \ No newline at end of file -- 2.11.0