Skip to content

Fix EventDateTime cast failing on date properties#52

Merged
chiiya merged 1 commit into
masterfrom
fix/event-datetime-types
May 29, 2026
Merged

Fix EventDateTime cast failing on date properties#52
chiiya merged 1 commit into
masterfrom
fix/event-datetime-types

Conversation

@chiiya

@chiiya chiiya commented May 29, 2026

Copy link
Copy Markdown
Owner

Problem

Fixes chiiya/laravel-passes#41.

Adding a dateTime (EventDateTime) to an EventTicketClass and decoding it throws:

EventDateTime::__construct(): Argument #1 ($doorsOpen) must be of type ?string, DateTimeImmutable given

Root cause

In Google\Components\EventTicket\EventDateTime, the doorsOpen, start and end properties carry #[Cast(ISO8601DateCaster::class)], but were typed ?string. DateCaster::unserialize() returns a DateTimeImmutable, which cannot be assigned to a ?string parameter during decode() — hence the TypeError.

This is the inverse of the issue fixed in #51: there the caster returned null into a non-nullable param; here it returns a DateTimeImmutable into a string param.

Fix

Type the three date properties DateTimeInterface|string|null, matching Common\DateTime::$date. The cast result now fits, and DateCaster::serialize() already handles both DateTimeInterface and string inputs, so building/encoding is unaffected (round-trip still emits canonical ISO8601 strings).

Tests

Added tests/Google/Components/EventTicket/EventDateTimeTest.php:

  • decoding ISO8601 strings yields DateTimeImmutable values
  • round-trip decode → serialize emits canonical ISO8601 strings
  • constructing with plain date strings still works

Full suite passes (54 tests); just lint clean.

EventDateTime's doorsOpen, start and end carry #[Cast(ISO8601DateCaster)],
whose unserialize() returns a DateTimeImmutable. The properties were typed
?string, so decoding threw a TypeError. Type them DateTimeInterface|string|null
to match Common\DateTime::$date.

Fixes chiiya/laravel-passes#41
@chiiya chiiya merged commit 5bcd0ac into master May 29, 2026
3 checks passed
@chiiya chiiya deleted the fix/event-datetime-types branch May 29, 2026 12:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cast in Chiiya\Passes\Google\Components\EventTicket\EventDateTime failed

1 participant