$periods */ public function __construct( private readonly array $periods, private readonly ClockInterface $clock, ) { } /** * The date range of a current period, matched case-insensitively, or null. * * @return array{from: \DateTimeImmutable, to: \DateTimeImmutable}|null */ public function find(string $label): ?array { foreach ($this->current() as $period) { if (0 === strcasecmp($period['label'], trim($label))) { return ['from' => new \DateTimeImmutable($period['from']), 'to' => new \DateTimeImmutable($period['to'])]; } } return null; } /** * @return list */ public function labels(): array { return array_column($this->current(), 'label'); } /** * @return list */ private function current(): array { $today = $this->clock->now()->setTimezone(new \DateTimeZone('Europe/Berlin'))->format('Y-m-d'); return array_values(array_filter($this->periods, static fn (array $period): bool => $period['to'] >= $today)); } }