PHP code example of crtl / openings

1. Go to this page and download the library: Download crtl/openings 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/ */

    

crtl / openings example snippets


[
    "key" => ["H:i-H:i", "H:i-H:i"],
    "key1, key1 , keyN" => ["H:i-H:i"],
    "key-key" => ["H:i-H:i"]
]




use Crtl\Openings\OpeningsManager;
use Crtl\Openings\Exceptions\InvalidFormatException;

"10:00-16:00"],
    "Sun" => [] //Closed, you can also asign any other false value
];

//Define opening exceptions
$exceptions = [
    "2017/12/24-2018/01/01" => [], //Closed  from 2017/12/24 to 2018/01/01
    "2018/01/02" => ["10:00-14:00"]
];

//Create instance
try {
    $openingsManager = new OpeningsManager($openings, $exceptions);
}
catch (InvalidFormatException $ex) {
    die($ex->getMessage()); //Invalid format supplied either  for keys or values
}

$openingsManager->isOpen() //same as $openingsManager->isOpen(new DateTime());
$openingsManager->isOpen($myDateTime);

$date = new \DateTime("2017-12-24 10:00:00");
$openingsManager->isOpen($date) 

$nextWeek = new \DateTime("09:00:00");
$nextWeek->add(new \DateInterval("P1W"));

$openingsManager->isOpen($nextWeek);