PHP code example of sdui / daterange

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

    

sdui / daterange example snippets


/*
 * Scope            |0--------------------------24>
 * Intersection
 * Gaps             {0           				24}
*/
$start = Carbon::make('2021-11-25')->startOfDay();
$end = $start->clone()->endOfDay();
$scope = new DateRange($start, $end);
$gaps = DateRange::gaps($scope, []);

count($gaps); 			// 1
$gaps[0]->getStart(); 	// 2021-11-25 00:00:00
$gaps[0]->getEnd(); 	// 2021-11-25 23:59:59

/*
 * Scope            |0--------------------------24>
 * Intersection     [0           9]
 * Gaps                            {9           24}
*/
$start = Carbon::make('2021-11-25')->startOfDay();
$end = $start->clone()->endOfDay();
$scope = new DateRange($start, $end);
$intersection = new DateRange($start->clone(), $start->clone()->setHour(9));
$gaps = DateRange::gaps($scope, [$intersection]);

count($gaps); 			// 1
$gaps[0]->getStart(); 	// 2021-11-25 00:00:00
$gaps[0]->getEnd(); 	// 2021-11-25 08:59:59