Add Events::fromDateStrings

This commit is contained in:
Oliver Davies 2025-06-15 09:58:14 +01:00
parent 678263c75c
commit 3ba181a753
4 changed files with 30 additions and 48 deletions

View file

@ -35,6 +35,27 @@ readonly final class Events implements \Countable, \IteratorAggregate {
->filter(fn (Event $event): bool => $event->isPast());
}
/**
* @param non-empty-string[] $events
*/
public static function fromDateStrings(string ...$dates): self {
$events = array_map(
array: $dates,
callback: fn (string $date): Event => Event::create([
'field_date' => strtotime($date),
]),
);
return new self($events);
}
/**
* @return Event[]
*/
public function toEvents(): array {
return $this->events;
}
/**
* @param Event[] $events
*/