Skip to content

Commit 8bfc1d6

Browse files
authored
Merge pull request #12 from Waghabond/master
Add support for history API v3 JSON response. PR #1
2 parents 1e046a7 + 4f68d41 commit 8bfc1d6

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

src/WeatherFormat.php

+13-5
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)