diff --git a/Cmfcmf/OpenWeatherMap/WeatherForecast.php b/Cmfcmf/OpenWeatherMap/WeatherForecast.php index 2fc6a6c..9264ea9 100644 --- a/Cmfcmf/OpenWeatherMap/WeatherForecast.php +++ b/Cmfcmf/OpenWeatherMap/WeatherForecast.php @@ -78,16 +78,8 @@ public function __construct($xml, $units, $days) $this->sun = new Sun(new \DateTime($xml->sun['rise'], $utctz), new \DateTime($xml->sun['set'], $utctz)); $this->lastUpdate = new \DateTime($xml->meta->lastupdate, $utctz); - $today = new \DateTime('now', $utctz); - $today->setTime(0, 0, 0); $counter = 0; foreach ($xml->forecast->time as $time) { - $date = new \DateTime(isset($time['day']) ? $time['day'] : $time['to'], $utctz); - if ($date < $today) { - // Sometimes OpenWeatherMap returns results which aren't real - // forecasts. The best we can do is to ignore them. - continue; - } $forecast = new Forecast($time, $units); $forecast->city = $this->city; $forecast->sun = $this->sun; diff --git a/tests/FakeData.php b/tests/FakeData.php index c6bd1d1..2890b39 100644 --- a/tests/FakeData.php +++ b/tests/FakeData.php @@ -65,7 +65,7 @@ public static function forecastXML() </meta> <sun rise="2016-12-28T07:17:18" set="2016-12-28T14:59:55"></sun> <forecast> - <time day="2016-12-20"> + <time day="' . date('Y-m-d', time() + 0) . '"> <symbol number="500" name="light rain" var="10d"></symbol> <precipitation value="0.25" type="rain"></precipitation> <windDirection deg="315" code="NW" name="Northwest"></windDirection> @@ -75,7 +75,7 @@ public static function forecastXML() <humidity value="97" unit="%"></humidity> <clouds value="overcast clouds" all="92" unit="%"></clouds> </time> - <time day="' . date('Y-m-d') . '"> + <time day="' . date('Y-m-d', time() + 3600) . '"> <symbol number="500" name="light rain" var="10d"></symbol> <precipitation value="0.24" type="rain"></precipitation> <windDirection deg="253" code="WSW" name="West-southwest"></windDirection> diff --git a/tests/OpenWeatherMap/WeatherForecastTest.php b/tests/OpenWeatherMap/WeatherForecastTest.php index e875f20..5530cd9 100644 --- a/tests/OpenWeatherMap/WeatherForecastTest.php +++ b/tests/OpenWeatherMap/WeatherForecastTest.php @@ -55,19 +55,12 @@ public function testCurrent() public function testNext() { - $this->forecast->rewind(); $this->forecast->next(); - $result = $this->forecast->valid(); - - $this->assertFalse($result); + $this->assertTrue($this->forecast->valid()); } public function testValid() { - $this->forecast->rewind(); - $this->forecast->next(); - $result = $this->forecast->valid(); - - $this->assertFalse($result); + $this->assertTrue($this->forecast->valid()); } }