From 988502cbdf39f6008d6577d2245627e5be99e3f0 Mon Sep 17 00:00:00 2001 From: Chuck Hagenbuch Date: Mon, 2 Feb 2009 23:57:02 -0500 Subject: [PATCH] initial hour/minute/second repeaters --- .../Date/Parser/Locale/Base/Repeater/Hour.php | 113 +++++++++++---------- .../Date/Parser/Locale/Base/Repeater/Minute.php | 109 ++++++++++---------- .../Date/Parser/Locale/Base/Repeater/Second.php | 81 ++++++++------- 3 files changed, 163 insertions(+), 140 deletions(-) diff --git a/framework/Date_Parser/lib/Horde/Date/Parser/Locale/Base/Repeater/Hour.php b/framework/Date_Parser/lib/Horde/Date/Parser/Locale/Base/Repeater/Hour.php index f13e385c6..598c004fb 100644 --- a/framework/Date_Parser/lib/Horde/Date/Parser/Locale/Base/Repeater/Hour.php +++ b/framework/Date_Parser/lib/Horde/Date/Parser/Locale/Base/Repeater/Hour.php @@ -1,57 +1,62 @@ currentHourStart) { + $this->currentHourStart = new Horde_Date(array('month' => $this->now->month, 'year' => $this->now->year, 'day' => $this->now->day, 'hour' => $this->now->hour)); + } + $this->currentHourStart->hour += $direction; + + $end = clone($this->currentHourStart); + $end->hour++; + return new Horde_Date_Span($this->currentHourStart, $end); + } + + public function this($pointer = 'future') + { + parent::this($pointer); + + switch ($pointer) { + case 'future': + $hourStart = new Horde_Date(array('year' => $this->month->year, 'month' => $this->now->month, 'day' => $this->now->day, 'hour' => $this->now->hour, 'min' => $this->now->min + 1)); + $hourEnd = new Horde_Date(array('year' => $this->month->year, 'month' => $this->now->month, 'day' => $this->now->day, 'hour' => $this->now->hour + 1)); + break; + + case 'past': + $hourStart = new Horde_Date(array('year' => $this->month->year, 'month' => $this->now->month, 'day' => $this->now->day, 'hour' => $this->now->hour)); + $hourEnd = new Horde_Date(array('year' => $this->month->year, 'month' => $this->now->month, 'day' => $this->now->day, 'hour' => $this->now->hour + 1, 'min' => $this->now->min)); + break; + + case 'none': + $hourStart = new Horde_Date(array('year' => $this->month->year, 'month' => $this->now->month, 'day' => $this->now->day, 'hour' => $this->now->hour)); + $hourEnd = clone($hourStart); + $hourEnd->hour++; + break; + } + + return new Horde_Date_Span($hourStart, $hourEnd); + } + + public function offset($span, $amount, $pointer) + { + $direction = ($pointer == 'future') ? 1 : -1; + return $span->add(array('hour' => $direction * $amount)); + } + + public function width() + { + return 3600; + } + + public function __toString() + { + return parent::__toString() . '-hour'; + } + +} diff --git a/framework/Date_Parser/lib/Horde/Date/Parser/Locale/Base/Repeater/Minute.php b/framework/Date_Parser/lib/Horde/Date/Parser/Locale/Base/Repeater/Minute.php index a15da641c..679cdf901 100644 --- a/framework/Date_Parser/lib/Horde/Date/Parser/Locale/Base/Repeater/Minute.php +++ b/framework/Date_Parser/lib/Horde/Date/Parser/Locale/Base/Repeater/Minute.php @@ -1,54 +1,61 @@ currentMinuteStart) { + $this->currentMinuteStart = new Horde_Date(array('month' => $this->now->month, 'year' => $this->now->year, 'day' => $this->now->day, 'hour' => $this->now->hour, 'min' => $this->now->min)); + } + $direction = ($pointer == 'future') ? 1 : -1; + $this->currentMinuteStart->min += $direction; + + $end = clone($this->currentMinuteStart); + $end->min++; + return new Horde_Date_Span($this->currentMinuteStart, $end); + } + + public function this($pointer = 'future') + { + parent::this($pointer); + + switch ($pointer) { + case 'future': + $minuteBegin = clone($this->now); + $minuteEnd = new Horde_Date(array('month' => $this->now->month, 'year' => $this->now->year, 'day' => $this->now->day, 'hour' => $this->now->hour, 'min' => $this->now->min)); + break; + + case 'past': + $minuteBegin = new Horde_Date(array('month' => $this->now->month, 'year' => $this->now->year, 'day' => $this->now->day, 'hour' => $this->now->hour, 'min' => $this->now->min)); + $minuteEnd = clone($this->now); + break; + + case 'none': + $minuteBegin = new Horde_Date(array('month' => $this->now->month, 'year' => $this->now->year, 'day' => $this->now->day, 'hour' => $this->now->hour, 'min' => $this->now->min)); + $minuteEnd = new Horde_Date(array('month' => $this->now->month, 'year' => $this->now->year, 'day' => $this->now->day, 'hour' => $this->now->hour, 'min' => $this->now->min + 1)); + break; + } + + return new Horde_Date_Span($minuteBegin, $minuteEnd); + } + + public function offset($span, $amount, $pointer) + { + $direction = ($pointer == 'future') ? 1 : -1; + return $span->add(array('min' => $diretion * $amount)); + } + + public function width() + { + return 60; + } + + public function __toString() + { + return parent::__toString() . '-minute'; + } + +} diff --git a/framework/Date_Parser/lib/Horde/Date/Parser/Locale/Base/Repeater/Second.php b/framework/Date_Parser/lib/Horde/Date/Parser/Locale/Base/Repeater/Second.php index f55c86571..a26bfe467 100644 --- a/framework/Date_Parser/lib/Horde/Date/Parser/Locale/Base/Repeater/Second.php +++ b/framework/Date_Parser/lib/Horde/Date/Parser/Locale/Base/Repeater/Second.php @@ -1,38 +1,49 @@ secondStart) { + $this->secondStart = clone($this->now); + $this->secondStart->sec += $direction; + } else { + $this->secondStart += $direction; + } + + $end = clone($this->secondStart); + $end->sec++; + return new Horde_Date_Span($this->secondStart, $end); + } + + public function this($pointer = 'future') + { + parent::this($pointer); + + $end = clone($this->now); + $end->sec++; + return new Horde_Date_Span($this->now, $end); + } + + public function offset($span, $amount, $pointer) + { + $direction = ($pointer == 'future') ? 1 : -1; + return $span->add($direction * $amount); + } + + public function width() + { + return 1; + } + + public function __toString() + { + return parent::__toString() . '-second'; + } + +} -- 2.11.0