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

Check availibility for appointments

amirakbulut opened this issue · comments

How would I check for available times in order to create appointments?

commented

If by "available", you mean not occupied by an other appointment, then you're out of the scope of the opening-hours library.

Basically, I would say you should use a DB table to save the list of the appointments. Then query the appointments for each day to display.

At this point the TimeRange class of opening-hours can help you:

$occupied = \Spatie\OpeningHours\TimeRange::fromString('08:00-10:00');
$ap1 = \Spatie\OpeningHours\TimeRange::fromString('09:00-10:00');
$ap2 = \Spatie\OpeningHours\TimeRange::fromString('10:00-11:00');

var_dump($occupied->overlaps($ap1));
var_dump($occupied->overlaps($ap2));

(You can also take a look at the overlaps() method of CarbonPeriod from the Carbon library).

If you mean something else, please specify your case with your open hours settings, your current code, a data sample and the output you expect for this sample.