From 9e632ab8ab8b32c52628d775bbf21125d2c4d3af Mon Sep 17 00:00:00 2001 From: florianv Date: Wed, 30 Jun 2021 14:13:53 +0300 Subject: [PATCH] fix: abstract api historical dates --- src/Service/AbstractApi.php | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/Service/AbstractApi.php b/src/Service/AbstractApi.php index 73ab113..6aa5bae 100644 --- a/src/Service/AbstractApi.php +++ b/src/Service/AbstractApi.php @@ -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()];