From: Michael J. Rubinsky Date: Tue, 9 Jun 2009 14:22:24 +0000 (-0400) Subject: Don't process weather data if we are out of range X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=5b3a2969fd7d471c95c7052b7789fa8e6d254ed7;p=horde.git Don't process weather data if we are out of range --- diff --git a/timeobjects/lib/Driver/Weatherdotcom.php b/timeobjects/lib/Driver/Weatherdotcom.php index c3e2e2163..929ec532e 100644 --- a/timeobjects/lib/Driver/Weatherdotcom.php +++ b/timeobjects/lib/Driver/Weatherdotcom.php @@ -64,14 +64,25 @@ class TimeObjects_Driver_Weatherdotcom extends TimeObjects_Driver /** * * @param mixed $start The start time of the period - * @param mixed $time The end time of the period + * @param mixed $end The end time of the period * * @return array of listTimeObjects arrays. */ - public function listTimeObjects($start = null, $time = null) + public function listTimeObjects($start = null, $end = null) { global $conf; + // No need to continue if the forecast days are not in the current + // range. + $forecast_start = new Horde_Date(time()); + $forecast_end = new Horde_Date($forecast_start); + // Today is day 1, so subtract a day + $forecast_end->mday += $this->_params['days'] - 1; + if ($end->compareDate($forecast_start) <= -1 || + $start->compareDate($forecast_end) >= 1) { + return array(); + } + if (!class_exists('Services_Weather') || !class_exists('Cache')) { throw new TimeObjects_Exception('Services_Weather or PEAR Cache Classes not found.'); } @@ -160,10 +171,9 @@ class TimeObjects_Driver_Weatherdotcom extends TimeObjects_Driver throw new TimeObjects_Exception($location->getMessage()); } - $now = new Horde_Date(time()); $objects = array(); foreach ($forecast['days'] as $which => $data) { - $day = new Horde_Date($now); + $day = new Horde_Date($forecast_start); $day->mday += $which; $day_end = new Horde_Date($day); $day_end->mday++;