Skip to content

Commit 6a9ecab

Browse files
committed
Merge pull request #25 from emmanuelroecker/weatherforecast-with-sunrise-and-sunset
Add sunrise and sunset in WeatherForecast Class
2 parents f184d31 + f982f88 commit 6a9ecab

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/.idea
12
/vendor
23
/composer.lock
34
/phpunit.phar

Cmfcmf/OpenWeatherMap/WeatherForecast.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
use Cmfcmf\OpenWeatherMap;
2222
use Cmfcmf\OpenWeatherMap\Util\City;
23+
use Cmfcmf\OpenWeatherMap\Util\Sun;
2324

2425
/**
2526
* Weather class returned by Cmfcmf\OpenWeatherMap->getWeather().
@@ -35,6 +36,13 @@ class WeatherForecast implements \Iterator
3536
*/
3637
public $city;
3738

39+
/**
40+
* A sun object
41+
*
42+
* @var Util\Sun
43+
*/
44+
public $sun;
45+
3846
/**
3947
* The time of the last update of this weather data.
4048
*
@@ -68,6 +76,7 @@ class WeatherForecast implements \Iterator
6876
public function __construct($xml, $units, $days)
6977
{
7078
$this->city = new City(-1, $xml->location->name, $xml->location->location['longitude'], $xml->location->location['latitude'], $xml->location->country);
79+
$this->sun = new Sun(new \DateTime($xml->sun['rise']), new \DateTime($xml->sun['set']));
7180
$this->lastUpdate = new \DateTime($xml->meta->lastupdate);
7281

7382
$counter = 0;

Examples/WeatherForecast.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@
4444
echo "<br />\n";
4545
echo "LastUpdate: " . $forecast->lastUpdate->format('d.m.Y H:i');
4646
echo "<br />\n";
47+
echo "Sunrise : " . $forecast->sun->rise->format("H:i:s") . " Sunset : " . $forecast->sun->set->format("H:i:s");
48+
echo "<br />\n";
4749
echo "<br />\n";
4850

4951
foreach ($forecast as $weather) {

0 commit comments

Comments
 (0)