Skip to content

Commit f5bc322

Browse files
author
Hennell
committed
Add timezone property to city.
1 parent 409bdc8 commit f5bc322

File tree

4 files changed

+14
-4
lines changed

4 files changed

+14
-4
lines changed

Cmfcmf/OpenWeatherMap/CurrentWeather.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public function __construct($data, $units)
104104
$utctz = new \DateTimeZone('UTC');
105105

106106
if ($data instanceof \SimpleXMLElement) {
107-
$this->city = new City($data->city['id'], $data->city['name'], $data->city->coord['lat'], $data->city->coord['lon'], $data->city->country);
107+
$this->city = new City($data->city['id'], $data->city['name'], $data->city->coord['lat'], $data->city->coord['lon'], $data->city->country, null, $data->city->timezone);
108108
$this->temperature = new Temperature(new Unit($data->temperature['value'], $data->temperature['unit']), new Unit($data->temperature['min'], $data->temperature['unit']), new Unit($data->temperature['max'], $data->temperature['unit']));
109109
$this->humidity = new Unit($data->humidity['value'], $data->humidity['unit']);
110110
$this->pressure = new Unit($data->pressure['value'], $data->pressure['unit']);
@@ -118,7 +118,7 @@ public function __construct($data, $units)
118118
$this->weather = new Weather($data->weather['number'], $data->weather['value'], $data->weather['icon']);
119119
$this->lastUpdate = new \DateTime($data->lastupdate['value'], $utctz);
120120
} else {
121-
$this->city = new City($data->id, $data->name, $data->coord->lat, $data->coord->lon, $data->sys->country);
121+
$this->city = new City($data->id, $data->name, $data->coord->lat, $data->coord->lon, $data->sys->country, null, $data->timezone);
122122
$this->temperature = new Temperature(new Unit($data->main->temp, $units), new Unit($data->main->temp_min, $units), new Unit($data->main->temp_max, $units));
123123
$this->humidity = new Unit($data->main->humidity, '%');
124124
$this->pressure = new Unit($data->main->pressure, 'hPa');

Cmfcmf/OpenWeatherMap/Util/City.php

+7-1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ class City extends Location
4343
*/
4444
public $population;
4545

46+
/**
47+
* @var int The shift in seconds from UTC
48+
*/
49+
public $timezone;
4650
/**
4751
* Create a new city object.
4852
*
@@ -52,15 +56,17 @@ class City extends Location
5256
* @param float $lon The longitude of the city.
5357
* @param string $country The abbreviation of the country the city is located in
5458
* @param int $population The city's population.
59+
* @param int $timezone The shift in seconds from UTC.
5560
*
5661
* @internal
5762
*/
58-
public function __construct($id, $name = null, $lat = null, $lon = null, $country = null, $population = null)
63+
public function __construct($id, $name = null, $lat = null, $lon = null, $country = null, $population = null, $timezone = null)
5964
{
6065
$this->id = (int)$id;
6166
$this->name = isset($name) ? (string)$name : null;
6267
$this->country = isset($country) ? (string)$country : null;
6368
$this->population = isset($population) ? (int)$population : null;
69+
$this->timezone = isset($timezone) ? (int)$timezone : null;
6470

6571
parent::__construct($lat, $lon);
6672
}

Cmfcmf/OpenWeatherMap/WeatherForecast.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ class WeatherForecast implements \Iterator
7474
*/
7575
public function __construct($xml, $units, $days)
7676
{
77-
$this->city = new City($xml->location->location['geobaseid'], $xml->location->name, $xml->location->location['latitude'], $xml->location->location['longitude'], $xml->location->country);
77+
$this->city = new City($xml->location->location['geobaseid'], $xml->location->name, $xml->location->location['latitude'], $xml->location->location['longitude'], $xml->location->country, null, $xml->location->timezone);
7878
$utctz = new \DateTimeZone('UTC');
7979
$this->sun = new Sun(new \DateTime($xml->sun['rise'], $utctz), new \DateTime($xml->sun['set'], $utctz));
8080
$this->lastUpdate = new \DateTime($xml->meta->lastupdate, $utctz);

tests/FakeData.php

+4
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ class FakeData
2323
const WEATHER_GROUP_JSON = '{
2424
"list":[{
2525
"id":1851632,
26+
"timezone": 32400,
2627
"dt":1406106000,
2728
"coord":{"lon":138.933334,"lat":34.966671},
2829
"sys":{"type":3,"id":168940,"message":0.0297,"country":"US","sunrise":1427723751,"sunset":1427768967},
@@ -43,6 +44,7 @@ class FakeData
4344
},{
4445
"id":1851633,
4546
"dt":1406106000,
47+
"timezone": 32400,
4648
"coord":{"lon":138.933334,"lat":34.966671},
4749
"sys":{"type":3,"id":168940,"message":0.0297,"country":"US","sunrise":1427723751,"sunset":1427768967},
4850
"name":"Shuzenji",
@@ -110,6 +112,7 @@ public static function forecastXML()
110112
<city id="2950159" name="Berlin">
111113
<coord lon="13.41" lat="52.52"></coord>
112114
<country>DE</country>
115+
<timezone>3600</timezone>
113116
<sun rise="2017-01-02T07:16:51" set="2017-01-02T15:04:50"></sun>
114117
</city>
115118
<temperature value="36.48" min="35.6" max="37.4" unit="fahrenheit"></temperature>
@@ -137,6 +140,7 @@ public static function forecastXML()
137140
<city id="2950159" name="Berlin">
138141
<coord lon="13.41" lat="52.52"></coord>
139142
<country>DE</country>
143+
<timezone>3600</timezone>
140144
<sun rise="2017-01-02T07:16:51" set="2017-01-02T15:04:50"></sun>
141145
</city>
142146
<temperature value="36.48" min="35.6" max="37.4" unit="fahrenheit"></temperature>

0 commit comments

Comments
 (0)