spatie / opening-hours

Query and format a set of opening hours

Home Page:https://freek.dev/595-managing-opening-hours-with-php

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Timezone not working

Atnaize opened this issue · comments

Hey,

I'm trying to setup the timezone when creating my OpeningHours object.

So I have this

OpeningHours::create([
            'monday'     => ['08:00-18:30'],
            ...
            'timezone' => [ new DateTimeZone("Europe/Brussels") ],
]);

Which is is mentioned here (https://github.com/spatie/opening-hours/blob/master/src/OpeningHours.php#L32)

But I have the following error

Day `timezone` isn't a valid day name. Valid day names are lowercase english words, e.g. `monday`, `thursday`.

This error is coming from Spatie\OpeningHours\Exceptions\InvalidDayName\invalidDayName. Is it normal?

Or maybe I didn't understood that well how to setup the timezone?

commented

Hello,

Timezone is a parameter of the create() method:
https://github.com/spatie/opening-hours#openinghourscreatearray-data-timezone--null-spatieopeninghoursopeninghours

It's not part of the array-definition of hours, here is an example:

$hours = \Spatie\OpeningHours\OpeningHours::create([
  'monday' => ['08:00-18:30'],
], new DateTimeZone('UTC'));

var_dump($hours->isOpenAt(new DateTime('2019-12-09 19:00', new DateTimeZone('Europe/Brussels'))));
// true in UTC

$hours = \Spatie\OpeningHours\OpeningHours::create([
  'monday' => ['08:00-18:30'],
], new DateTimeZone('Europe/Brussels'));

var_dump($hours->isOpenAt(new DateTime('2019-12-09 19:00', new DateTimeZone('Europe/Brussels'))));
// false in Brussels

Thanks,