PHP code example of danoha / date-range

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

    

danoha / date-range example snippets


$range = new \Danoha\DateRange($from, $to); // any parameter can be NULL
$range
    ->join($thatRange)
    ->intersect([ $from, $to ]) // methods accepting range also accept array
    ->contains($currentDate);

$coll = new \Danoha\DateRangeCollection([
    [ $from, $to ], // two items per range accepted
    [ 'from' => $from, 'to' => $to, ], // accepted too
    
    [ $from, NULL, ], // NULL means indefinite interval
    [ NULL, NULL, ], // and can be used on both sides
]);

$coll
    ->join($thatCollection)
    ->intersect([ $range1, $range2 ]) // methods accepting collection also accept array
    ->contains($someRange);

$coll->getRanges() === [
    new \Danoha\DateRange($from, $to),
    new \Danoha\DateRange($from, NULL),
];

$coll->unwrap() === [
    [ 'from' => $from, 'to' => $to, ], // every range has this exact format
    [ 'from' => $from, 'to' => NULL, ], // regardless of what was passed to constructor
    ...
];

$coll->intersect(
    // another collection
    new \Danoha\DateRangeCollection([ ... ])
);

$coll->intersect([
    // inlined collection (same as constructor)
    [ 'from' => $from, 'to' => $to, ]
]);