PHP code example of rflex / period

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

    

rflex / period example snippets


use Rflex\Period;
use Rflex\Event; // Extension of the Carbon class.

$period->addDay(true, false); // Add a day to the start of the period.
$period->addDays(5, true, false); // Add five days to the start of the period.

$period->subDay(false, true); // Subtract a day to the end of the period.
$period->subDays(3, false, true); // Subtract three days to the end of the period.

$period->getSeconds();

$period->getMinutes();

$period->getHours();

$period = Period::between(Carbon::now(), Carbon::now()->addDay());
$period2 = Period::between(carbon::now(), Carbon::now()->addDays(2));
$unifiedPeriod = $period->union($period2); // Returns a new unified Period.

$period = Period::between(Carbon::now(), Carbon::now()->addDay());
$period2 = Period::between(carbon::now(), Carbon::now()->addDays(2));
$intersection = $period->intersection($period2); // Returns a new intersected Period.

$period = Period::between(Carbon::now(), Carbon::now()->addDay());
$period2 = Period::between(carbon::now(), Carbon::now()->addDays(2));
$period->intersects($period2); // Returns true.

$period = Period::between(Carbon::now(), Carbon::now()->addDay());
$period2 = Period::between(carbon::now(), Carbon::now()->addDays(2));
$unifiedPeriod = $period->difference($period2); // Returns an array.

$period = Period::between(Carbon::now(), Carbon::now()->addDay());
$event = Event::create(carbon::now());
$seconds = $period->differenceWithEvent($event); // Returns the difference between the two in seconds.

$period->setLengthInSeconds(3600);

$period->setLengthInMinutes(700);

$period->setLengthInHours(48);