www
This commit is contained in:
@@ -10,7 +10,6 @@ use Carbon\CarbonPeriod;
|
|||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
use Illuminate\Support\Arr;
|
use Illuminate\Support\Arr;
|
||||||
use Illuminate\Support\Carbon;
|
use Illuminate\Support\Carbon;
|
||||||
use Illuminate\Support\Facades\Log;
|
|
||||||
use Investbrain\Frankfurter\Frankfurter;
|
use Investbrain\Frankfurter\Frankfurter;
|
||||||
|
|
||||||
class CurrencyRate extends Model
|
class CurrencyRate extends Model
|
||||||
@@ -161,11 +160,12 @@ class CurrencyRate extends Model
|
|||||||
|
|
||||||
// loop through each date
|
// loop through each date
|
||||||
$updates = [];
|
$updates = [];
|
||||||
|
$datesWithRates = array_keys($rates);
|
||||||
|
sort($datesWithRates);
|
||||||
|
|
||||||
foreach ($period as $date) {
|
foreach ($period as $date) {
|
||||||
|
|
||||||
$lookupDate = self::getNearestPastDate($date, $rates);
|
$lookupDate = self::getNearestPastDate($date, $datesWithRates);
|
||||||
|
|
||||||
Log::warning($lookupDate.' - '.isset($rates[$lookupDate->toDateString()]));
|
|
||||||
|
|
||||||
if (is_null($lookupDate)) {
|
if (is_null($lookupDate)) {
|
||||||
continue;
|
continue;
|
||||||
@@ -204,14 +204,12 @@ class CurrencyRate extends Model
|
|||||||
|
|
||||||
private static function getNearestPastDate(CarbonInterface $date, array $rates): ?CarbonInterface
|
private static function getNearestPastDate(CarbonInterface $date, array $rates): ?CarbonInterface
|
||||||
{
|
{
|
||||||
$datesWithRates = array_keys($rates);
|
|
||||||
sort($datesWithRates);
|
|
||||||
|
|
||||||
// get rates or find closest valid rate (handles missing weekend rates)
|
// get rates or find closest valid rate (handles missing weekend rates)
|
||||||
while (! isset($rates[$date->toDateString()])) {
|
while (! isset($rates[$date->toDateString()])) {
|
||||||
|
|
||||||
// is this the start of a range that falls on a weekend?
|
// is this the start of a range that falls on a weekend?
|
||||||
if ($date->lessThan($first_date = Carbon::parse($datesWithRates[0]))) {
|
if ($date->lessThan($first_date = Carbon::parse($rates[0]))) {
|
||||||
|
|
||||||
$date = $first_date;
|
$date = $first_date;
|
||||||
break;
|
break;
|
||||||
|
|||||||
Reference in New Issue
Block a user