Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for history API v3 JSON response. PR #1 #12

Merged
merged 2 commits into from
Nov 30, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions src/WeatherFormat.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ public function __construct()
/**
* format date based on configuration.
*
* @param string $timestamp, string $tz
* @param string $timestamp, int $tz
* @return string
*/
public function dt(string $timestamp, string $tz)
public function dt(string $timestamp, int $tz)
{
return date($this->dateFormat, ($timestamp + $tz));
return date($this->dateFormat, $timestamp + $tz);
}

public function formatCurrent($res)
Expand Down Expand Up @@ -95,14 +95,22 @@ public function formatHistorical($res)
{
$tz = $res->timezone_offset;

// modify date of current data
// Historical data response structure is different in One Call API v3.0
// timestamps returned
if (config('openweather.historical_api_version', '2.5') == '3.0') {
// modify date of current data
$res->data[0]->sunrise = $this->dt($res->data[0]->sunrise, $tz);
$res->data[0]->sunset = $this->dt($res->data[0]->sunset, $tz);
$res->data[0]->dt = $this->dt($res->data[0]->dt, $tz);
return $res;
}

// modify date of current data
$res->current->sunrise = $this->dt($res->current->sunrise, $tz);
$res->current->sunset = $this->dt($res->current->sunset, $tz);
$res->current->dt = $this->dt($res->current->dt, $tz);

// modify date of hourly data

foreach ($res->hourly as $key => $val) {
$res->hourly[$key]->dt = $this->dt($val->dt, $tz);
}
Expand Down