spatie/opening-hours

Question: How is that valid ?

JexPY opened this issue · 2 comments

JexPY commented
// Add the use at the top of each file where you want to use the OpeningHours class:
use Spatie\OpeningHours\OpeningHours;

$openingHours = OpeningHours::create([
    'monday'     => ['09:00-12:00', '13:00-18:00', '19:00-18:00'],
    'tuesday'    => ['22:00-05:00']
]);

$now = now(); // 2021-11-16 22:16:41.992490 Europe/Berlin (+01:00)
$range = $openingHours->currentOpenRange($now);

if ($range) {
    dd("It's open since ".$range->start()->format('l H:i')."\n", "It will close at ".$range->end()->format('l H:i')."\n");
} else {
    dd("It's closed since ".$openingHours->previousClose($now)->format('l H:i')."\n",
    "It will re-open at ".$openingHours->nextOpen($now)->format('l H:i')."\n");
}

// The output: It's open since Thursday 22:00, It will close at Thursday 07:00
// its ok?

I did not get the logic behind 19:00-18:00 how it can be start time 19:00 and end time 18:00 for Monday and for example 22:00-07:00 for Tuesday ?

Give me a little explanation, thank you in advance.

JexPY commented

@kylekatarnls Hi, great package but should I validate this start and end range by myself?

Actually if you pass 19:00-18:00, it's the same as for 22:00-05:00

As soon as the end hour is lower than start hour, we assume you want the range until this hour on the next day.

As explained the in the README:

On construction you can set a flag for overflowing times across days. For example, for a night club opens until 3am on Friday and Saturday:

$openingHours = \Spatie\OpeningHours\OpeningHours::create([
    'overflow' => true,
    'friday'   => ['20:00-03:00'],
    'saturday' => ['20:00-03:00'],
], null);