Add Events::fromDateStrings
This commit is contained in:
parent
678263c75c
commit
3ba181a753
4 changed files with 30 additions and 48 deletions
|
@ -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
|
||||
*/
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue