@@ -15,12 +15,12 @@ public function __construct()
15
15
/**
16
16
* format date based on configuration.
17
17
*
18
- * @param string $timestamp, string $tz
18
+ * @param string $timestamp, int $tz
19
19
* @return string
20
20
*/
21
- public function dt (string $ timestamp , string $ tz )
21
+ public function dt (string $ timestamp , int $ tz )
22
22
{
23
- return date ($ this ->dateFormat , ( $ timestamp + $ tz) );
23
+ return date ($ this ->dateFormat , $ timestamp + $ tz );
24
24
}
25
25
26
26
public function formatCurrent ($ res )
@@ -95,14 +95,22 @@ public function formatHistorical($res)
95
95
{
96
96
$ tz = $ res ->timezone_offset ;
97
97
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
+ }
99
107
108
+ // modify date of current data
100
109
$ res ->current ->sunrise = $ this ->dt ($ res ->current ->sunrise , $ tz );
101
110
$ res ->current ->sunset = $ this ->dt ($ res ->current ->sunset , $ tz );
102
111
$ res ->current ->dt = $ this ->dt ($ res ->current ->dt , $ tz );
103
112
104
113
// modify date of hourly data
105
-
106
114
foreach ($ res ->hourly as $ key => $ val ) {
107
115
$ res ->hourly [$ key ]->dt = $ this ->dt ($ val ->dt , $ tz );
108
116
}
0 commit comments