@@ -15,12 +15,12 @@ public function __construct()
1515 /**
1616 * format date based on configuration.
1717 *
18- * @param string $timestamp, string $tz
18+ * @param string $timestamp, int $tz
1919 * @return string
2020 */
21- public function dt (string $ timestamp , string $ tz )
21+ public function dt (string $ timestamp , int $ tz )
2222 {
23- return date ($ this ->dateFormat , ( $ timestamp + $ tz) );
23+ return date ($ this ->dateFormat , $ timestamp + $ tz );
2424 }
2525
2626 public function formatCurrent ($ res )
@@ -95,14 +95,22 @@ public function formatHistorical($res)
9595 {
9696 $ tz = $ res ->timezone_offset ;
9797
98- // modify date of current data
98+ // Historical data response structure is different in One Call API v3.0
99+ // timestamps returned
100+ if (config ('openweather.historical_api_version ' , '2.5 ' ) == '3.0 ' ) {
101+ // modify date of current data
102+ $ res ->data [0 ]->sunrise = $ this ->dt ($ res ->data [0 ]->sunrise , $ tz );
103+ $ res ->data [0 ]->sunset = $ this ->dt ($ res ->data [0 ]->sunset , $ tz );
104+ $ res ->data [0 ]->dt = $ this ->dt ($ res ->data [0 ]->dt , $ tz );
105+ return $ res ;
106+ }
99107
108+ // modify date of current data
100109 $ res ->current ->sunrise = $ this ->dt ($ res ->current ->sunrise , $ tz );
101110 $ res ->current ->sunset = $ this ->dt ($ res ->current ->sunset , $ tz );
102111 $ res ->current ->dt = $ this ->dt ($ res ->current ->dt , $ tz );
103112
104113 // modify date of hourly data
105-
106114 foreach ($ res ->hourly as $ key => $ val ) {
107115 $ res ->hourly [$ key ]->dt = $ this ->dt ($ val ->dt , $ tz );
108116 }
0 commit comments