feat(ticketing): resolve validity in tenant timezone

This commit is contained in:
2026-09-21 15:19:09 -03:00
parent f4de2ff5b2
commit 3e3b3bfac0
17 changed files with 354 additions and 45 deletions

View File

@@ -47,30 +47,42 @@ class ValidityTime extends Model
public function startsAt(
?CarbonInterface $at = null,
string $timezone = 'UTC',
): ?CarbonInterface {
if ($this->type === ValidityTimeType::FixedWindow) {
return $this->fixed_starts_at;
}
return $this->atCurrentDate($this->start_time, $at);
return $this->atCurrentDate($this->start_time, $at, $timezone);
}
public function expiresAt(
?CarbonInterface $at = null,
string $timezone = 'UTC',
): ?CarbonInterface {
if ($this->type === ValidityTimeType::FixedWindow) {
return $this->fixed_expires_at;
}
return $this->atCurrentDate($this->end_time, $at);
return $this->atCurrentDate($this->end_time, $at, $timezone);
}
public function isValid(
?CarbonInterface $at = null,
string $timezone = 'UTC',
): bool {
$at ??= now();
$startsAt = $this->startsAt($at);
$expiresAt = $this->expiresAt($at);
$startsAt = $this->startsAt($at, $timezone);
$expiresAt = $this->expiresAt($at, $timezone);
if ($this->type === ValidityTimeType::TimeWindow
&& $startsAt !== null && $expiresAt !== null && $expiresAt->lessThanOrEqualTo($startsAt)) {
if ($at->lessThan($expiresAt)) {
$startsAt = $startsAt->subDay();
} else {
$expiresAt = $expiresAt->addDay();
}
}
return ($startsAt === null || $startsAt->lessThanOrEqualTo($at))
&& ($expiresAt === null || $expiresAt->greaterThan($at));
@@ -79,6 +91,7 @@ class ValidityTime extends Model
private function atCurrentDate(
?string $time,
?CarbonInterface $at,
string $timezone,
): ?CarbonInterface {
if ($time === null) {
return null;
@@ -86,8 +99,9 @@ class ValidityTime extends Model
$at ??= now();
$localDate = CarbonImmutable::instance($at)
->setTimezone($timezone)
->format('Y-m-d');
return CarbonImmutable::parse($localDate.' '.$time);
return CarbonImmutable::parse($localDate.' '.$time, $timezone);
}
}