Get values when 0

This commit is contained in:
Juan Pablo Vial
2025-10-03 12:09:54 -03:00
parent fe8bbb5767
commit ecae3147d4
4 changed files with 9 additions and 5 deletions

View File

@ -53,7 +53,7 @@ class Money
} }
try { try {
$this->data[$provider] = (array) $this->fetchRedis($redisService, $redisKey); $this->data[$provider] = (array) $this->fetchRedis($redisService, $redisKey);
if (!isset($this->data[$provider][$date->format('Y-m-d')])) { if (!isset($this->data[$provider][$date->format('Y-m-d')]) or $this->data[$provider][$date->format('Y-m-d')] === 0) {
throw new EmptyRedis($redisKey); throw new EmptyRedis($redisKey);
} }
} catch (EmptyRedis) { } catch (EmptyRedis) {

View File

@ -21,7 +21,7 @@ class IPC
$ipcs = []; $ipcs = [];
try { try {
$ipcs = json_decode($this->redisService->get($this->redisKey), JSON_OBJECT_AS_ARRAY); $ipcs = json_decode($this->redisService->get($this->redisKey), JSON_OBJECT_AS_ARRAY);
if (!isset($ipcs[$dateKey])) { if (!isset($ipcs[$dateKey]) or $ipcs[$dateKey] === 0) {
throw new EmptyRedis($this->redisKey); throw new EmptyRedis($this->redisKey);
} }
} catch (EmptyRedis) { } catch (EmptyRedis) {

View File

@ -22,7 +22,7 @@ class UF
if ($date === null) { if ($date === null) {
$date = new DateTimeImmutable(); $date = new DateTimeImmutable();
} }
if ($date->diff($today)->days < 0) { if ($date->diff($today)->invert === 1) {
return 0.0; return 0.0;
} }
/** /**
@ -32,7 +32,7 @@ class UF
*/ */
try { try {
$ufs = $this->getRedisUFs(); $ufs = $this->getRedisUFs();
if (!isset($ufs[$date->format('Y-m-d')])) { if (!isset($ufs[$date->format('Y-m-d')]) or $ufs[$date->format('Y-m-d')] === 0) {
throw new EmptyRedis($this->redisKey); throw new EmptyRedis($this->redisKey);
} }
return $ufs[$date->format('Y-m-d')]; return $ufs[$date->format('Y-m-d')];
@ -54,12 +54,16 @@ class UF
} }
public function updateMany(array $dates): array public function updateMany(array $dates): array
{ {
$today = new DateTimeImmutable();
$ufs = []; $ufs = [];
try { try {
$ufs = json_decode($this->redisService->get($this->redisKey), JSON_OBJECT_AS_ARRAY); $ufs = json_decode($this->redisService->get($this->redisKey), JSON_OBJECT_AS_ARRAY);
} catch (EmptyRedis) {} } catch (EmptyRedis) {}
$updated = []; $updated = [];
foreach ($dates as $date) { foreach ($dates as $date) {
if ($date->diff($today)->invert === 1) {
continue;
}
if (!isset($ufs[$date->format('Y-m-d')]) or $ufs[$date->format('Y-m-d')] === 0) { if (!isset($ufs[$date->format('Y-m-d')]) or $ufs[$date->format('Y-m-d')] === 0) {
$uf = $this->moneyService->getUF($date); $uf = $this->moneyService->getUF($date);
if ($uf === 0.0) { if ($uf === 0.0) {

View File

@ -19,7 +19,7 @@ class USD
$usds = []; $usds = [];
try { try {
$usds = json_decode($this->redisService->get($this->redisKey), JSON_OBJECT_AS_ARRAY); $usds = json_decode($this->redisService->get($this->redisKey), JSON_OBJECT_AS_ARRAY);
if (!isset($usds[$date->format('Y-m-d')])) { if (!isset($usds[$date->format('Y-m-d')]) or $usds[$date->format('Y-m-d')] === 0) {
throw new EmptyRedis($this->redisKey); throw new EmptyRedis($this->redisKey);
} }
$usd = $usds[$date->format('Y-m-d')]; $usd = $usds[$date->format('Y-m-d')];