---
title: "Importing week arrays — Opening Hours for Laravel | Roundly"
description: "Import hours stored in the widely used weekday-keyed array format, with labels and exceptions — a data import, not a rewrite."
url: https://roundly-consulting.com/open-source/docs/opening-hours-for-laravel/importing-week-arrays
language: en
---

[All packages](https://roundly-consulting.com/open-source.md)

[Opening Hours for Laravel](https://roundly-consulting.com/open-source/docs/opening-hours-for-laravel.md)

# Importing week arrays

The widely used weekday-keyed array format is read natively, so switching from an older solution is a data import rather than a rewrite:

```php
use RoundlyConsulting\OpeningHours\DataTransferObjects\CalendarData;
use RoundlyConsulting\OpeningHours\Facades\OpeningHours;
use RoundlyConsulting\OpeningHours\Validation\ParseOptions;

$data = CalendarData::fromWeekArray([
    'monday' => ['09:00-12:00', ['hours' => '13:00-18:00', 'data' => 'Afternoon']],
    'exceptions' => [
        '2026-12-24' => [],
        '12-25' => ['data' => 'Christmas'],
        '2026-12-27 to 2026-12-30' => ['10:00-12:00'],
    ],
], new ParseOptions(mergeOverlapping: true));

OpeningHours::sync($clinic, $data);   // or $clinic->setOpeningHours($data)
```

- data on a range or a day is kept — a string becomes the label, an array the meta.
- Exception keys: Y-m-d (one-off), m-d (yearly), and Y-m-d to Y-m-d or m-d to m-d spans; \[\] or an entry without hours means closed.
- overflow is ignored — overnight ranges always run past midnight.
- With mergeOverlapping, a range that overlaps nothing is kept exactly as given; a merged range keeps a label, capacity or meta entry only when every range it absorbed agrees on it.
- filters is rejected (unsupported\_week\_array\_feature) — use a DynamicExceptionProvider instead.

## Validate before importing

WeekArrayParser returns a ParseResult instead of throwing, so one bad record doesn’t abort a batch import; violation paths use the legacy keys, and an invalid span bound is named on its own (exceptions.2026-12-01 to 2026-12-30.from or .until):

```php
use RoundlyConsulting\OpeningHours\Validation\WeekArrayParser;

$result = WeekArrayParser::parse($weekArray);   // ParseResult — never throws
$result->isValid();
$result->violations;                            // paths use the legacy keys: mon.0, exceptions.2026-12-24.0
$result->dataOrFail();                          // CalendarData
```

## Show your open-source love

This package is free and MIT-licensed. If it saves you time, a one-off donation or a Patreon membership keeps it maintained, tested and documented.

[More ways to support, including crypto](https://roundly-consulting.com/support-us.md)

By donating, you agree to our [donation terms](https://roundly-consulting.com/donation-terms.md).

[Support our open source work (opens in a new tab)](https://donate.stripe.com/dRmeVe8FX5PF1Qd9pXcEw00) [Join us on Patreon (opens in a new tab)](https://www.patreon.com/cw/roundly)

## Want this built into your product?

We integrate our packages into custom Laravel and AI builds. Tell us what you're working on and we'll reply within 48 hours.

[Get a quote in 48 hours](https://roundly-consulting.com/contact.md) [Browse all packages](https://roundly-consulting.com/open-source/docs/opening-hours-for-laravel.md)
