feat(ticketing): resolve validity in tenant timezone
This commit is contained in:
@@ -17,7 +17,7 @@ use Illuminate\Support\Collection;
|
||||
final readonly class ResolvedValidityGroup
|
||||
{
|
||||
/** @param Collection<int, ValidityTime> $validityTimes */
|
||||
public function __construct(public Collection $validityTimes) {}
|
||||
public function __construct(public Collection $validityTimes, public string $timezone = 'UTC') {}
|
||||
|
||||
/** Comprueba si el instante pertenece a la intersección efectiva del grupo. */
|
||||
public function isValid(?CarbonInterface $at = null): bool
|
||||
@@ -50,7 +50,17 @@ final readonly class ResolvedValidityGroup
|
||||
$anchor = $this->dateAnchor() ?? $at;
|
||||
|
||||
return $this->validityTimes
|
||||
->map(fn (ValidityTime $validityTime): ?CarbonInterface => $validityTime->startsAt($anchor))
|
||||
->map(function (ValidityTime $validityTime) use ($anchor): ?CarbonInterface {
|
||||
$start = $validityTime->startsAt($anchor, $this->timezone);
|
||||
$end = $validityTime->expiresAt($anchor, $this->timezone);
|
||||
|
||||
if ($this->dateAnchor() === null && $start !== null && $end !== null
|
||||
&& $end->lessThanOrEqualTo($start) && $anchor->lessThan($end)) {
|
||||
return $start->copy()->subDay();
|
||||
}
|
||||
|
||||
return $start;
|
||||
})
|
||||
->filter()
|
||||
->sortByDesc(fn (CarbonInterface $startsAt): int => $startsAt->getTimestamp())
|
||||
->first();
|
||||
@@ -67,11 +77,13 @@ final readonly class ResolvedValidityGroup
|
||||
|
||||
return $this->validityTimes
|
||||
->map(function (ValidityTime $validityTime) use ($anchor): ?CarbonInterface {
|
||||
$startsAt = $validityTime->startsAt($anchor);
|
||||
$expiresAt = $validityTime->expiresAt($anchor);
|
||||
$startsAt = $validityTime->startsAt($anchor, $this->timezone);
|
||||
$expiresAt = $validityTime->expiresAt($anchor, $this->timezone);
|
||||
|
||||
if ($startsAt !== null && $expiresAt !== null && $expiresAt->lessThanOrEqualTo($startsAt)) {
|
||||
return $expiresAt->addDay();
|
||||
return $this->dateAnchor() === null && $anchor->lessThan($expiresAt)
|
||||
? $expiresAt
|
||||
: $expiresAt->copy()->addDay();
|
||||
}
|
||||
|
||||
return $expiresAt;
|
||||
|
||||
Reference in New Issue
Block a user