PHP code example of shineunited / silex-timeline

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

    

shineunited / silex-timeline example snippets




ilex\Application;
use ShineUnited\Silex\Timeline\TimelineServiceProvider;

$app = new Application();

$app->register(new TimelineServiceProvider(), [
	'timeline.timezone' => 'UTC',
	'timeline.epochs'   => [
		'epoch1' => 'Monday, 15-Aug-2005 15:52:01',
		'epoch2' => '2005-08-15T15:52:01',
		'epoch3' => new \DateTimeImmutable('15-Aug-05 15:52:01')
	]
]);



// add epochs directly
$app['timeline']['epoch4'] = 'Monday, 15-Aug-2005 15:52:01';
$app['timeline']['epoch5'] = '15 Aug 2005 15:52:01';
$app['timeline']['epoch6'] = new \DateTimeImmutable('15-Aug-05 15:52:01');



$app['timeline']['now'];
$app['timeline']['epoch1'];
$app['timeline']['epoch2'];
$app['timeline']['epoch3'];



$app['timeline']->now;
$app['timeline']->epoch1;
$app['timeline']->epoch2;
$app['timeline']->epoch3;



// isBefore
if($app['timeline']->isBefore('epoch1')) {
	// before 'epoch1'
}

// isAfter
if($app['timeline']->isAfter('epoch1')) {
	// before 'epoch1'
}

// isUpcoming
if($app['timeline']->isUpcoming('epoch1')) {
	// before 'epoch1'
}

// isComplete
if($app['timeline']->isComplete('epoch1')) {
	// before 'epoch1'
}


// isBefore
if($epoch->isBefore('epoch1')) {
	// $epoch is before 'epoch1'
}

// isAfter
if($epoch->isAfter('epoch1')) {
	// $epoch is after 'epoch1'
}



// by array reference
if($app['timeline']['now'] < $app['timeline']['epoch1']) {
	// before 'epoch1'
}

if($app['timeline']['now'] >= $app['timeline']['epoch1']) {
	// after 'epoch1'
}

// by param reference
if($app['timeline']->now < $app['timeline']->epoch1) {
	// before 'epoch1'
}

if($app['timeline']->now >= $app['timeline']->epoch1) {
	// before 'epoch1'
}