PHP code example of phil / opening-hours

1. Go to this page and download the library: Download phil/opening-hours library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

phil / opening-hours example snippets


use Phil\OpeningHours\HoursText;
use Phil\OpeningHours\OpeningHours;

$weekday = HoursText::day('09:00-12:00, 13:00-17:00');
$hours = OpeningHours::of(
    [1 => $weekday, 2 => $weekday, 3 => $weekday, 4 => $weekday, 5 => HoursText::day('09:00-17:00, 20:00-02:00')],
    HoursText::specials("2026-12-25 # Christmas"),
    'America/Toronto',
);

$hours->isOpenAt(new DateTimeImmutable());   // true or false
$hours->nextOpening(new DateTimeImmutable()); // the next opening, in Toronto