Skip to content

Commit

Permalink
fix: abstract api historical dates
Browse files Browse the repository at this point in the history
  • Loading branch information
florianv committed Jun 30, 2021
1 parent baa98b9 commit 9e632ab
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions src/Service/AbstractApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,16 @@ private function doCreateRate($url, CurrencyPair $currencyPair): ExchangeRate
$data = StringUtil::jsonToArray($content);

if (isset($data['exchange_rates'][$currencyPair->getQuoteCurrency()])) {
$date = new \DateTime();
$date->setTimezone(new \DateTimeZone('UTC'));

if (isset($data['last_updated'])) {
$date->setTimestamp($data['last_updated']);
}

if (isset($data['date'])) {
$date = \DateTime::createFromFormat('Y-m-d', $data['date'], new \DateTimeZone('UTC'));
$date = \DateTime::createFromFormat(
'Y-m-d',
$data['date'],
new \DateTimeZone('UTC')
);
} else {
$date = new \DateTime();
$date->setTimezone(new \DateTimeZone('UTC'));
$date->setTimestamp($data['last_updated']);
}

$rate = $data['exchange_rates'][$currencyPair->getQuoteCurrency()];
Expand Down

0 comments on commit 9e632ab

Please sign in to comment.