FIX: IPC no disponible

This commit is contained in:
2023-12-04 19:51:44 -03:00
parent 9aa4e0ae1d
commit 43977d1bd9
3 changed files with 16 additions and 2 deletions

View File

@ -16,7 +16,7 @@ class Terreno implements JsonSerializable
return [
'superficie' => $this->superficie,
'valor' => $this->valor,
'date' => $this->fecha?->format('Y-m-d')
'fecha' => $this->fecha?->format('Y-m-d')
];
}
}

View File

@ -26,6 +26,9 @@ class IPC
}
} catch (EmptyRedis) {
$ipc = $this->moneyService->getIPC($from, $to);
if ($ipc === -1.0) {
return 0;
}
$ipcs[$dateKey] = $ipc;
ksort($ipcs);
$this->redisService->set($this->redisKey, json_encode($ipcs), 60 * 60 * 24 * 30);
@ -34,6 +37,9 @@ class IPC
}
public function readjust(float $base, DateTimeInterface $from, DateTimeInterface $to = new DateTimeImmutable()):float
{
return $base * (1 + $this->get($from, $to->sub(new DateInterval('P1M'))));
if (($ipc = $this->get($from, $to->sub(new DateInterval('P1M')))) === 0.0) {
return 0;
}
return $base * (1 + $ipc);
}
}