Skip to content

Commit daf760e

Browse files
committed
1 parent 57732d4 commit daf760e

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

Cmfcmf/OpenWeatherMap.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ public function getApiKey()
155155
}
156156

157157
/**
158-
* Returns the current weather at the place you specified as an object.
158+
* Returns the current weather at the place you specified.
159159
*
160160
* @param array|int|string $query The place to get weather information for. For possible values see below.
161161
* @param string $units Can be either 'metric' or 'imperial' (default). This affects almost all units returned.
@@ -183,7 +183,8 @@ public function getWeather($query, $units = 'imperial', $lang = 'en', $appid = '
183183
}
184184

185185
/**
186-
* Returns the current weather at the place you specified as an object.
186+
* Returns the forecast for the place you specified. DANGER: Might return
187+
* fewer results than requested due to a bug in the OpenWeatherMap API!
187188
*
188189
* @param array|int|string $query The place to get weather information for. For possible values see ::getWeather.
189190
* @param string $units Can be either 'metric' or 'imperial' (default). This affects almost all units returned.
@@ -213,7 +214,7 @@ public function getWeatherForecast($query, $units = 'imperial', $lang = 'en', $a
213214
}
214215

215216
/**
216-
* Returns the weather history for the place you specified as an object.
217+
* Returns the weather history for the place you specified.
217218
*
218219
* @param array|int|string $query The place to get weather information for. For possible values see ::getWeather.
219220
* @param \DateTime $start

Cmfcmf/OpenWeatherMap/WeatherForecast.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,16 @@ public function __construct($xml, $units, $days)
7878
$this->sun = new Sun(new \DateTime($xml->sun['rise']), new \DateTime($xml->sun['set']));
7979
$this->lastUpdate = new \DateTime($xml->meta->lastupdate);
8080

81+
$today = new \DateTime();
82+
$today->setTime(0, 0, 0);
8183
$counter = 0;
8284
foreach ($xml->forecast->time as $time) {
85+
$date = new \DateTime(isset($time['day']) ? $time['day'] : $time['to']);
86+
if ($date < $today) {
87+
// Sometimes OpenWeatherMap returns results which aren't real
88+
// forecasts. The best we can do is to ignore them.
89+
continue;
90+
}
8391
$forecast = new Forecast($time, $units);
8492
$forecast->city = $this->city;
8593
$this->forecasts[] = $forecast;

0 commit comments

Comments
 (0)