PHP code example of marsapp / timeperiodhelper

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

    

marsapp / timeperiodhelper example snippets




// Namespace use
use marsapp\helper\timeperiod\TimePeriodHelper;

// Get time periods. Maybe the data is confusing.
$workTimeperiods = [
    ['2019-01-04 13:00:30','2019-01-04 17:00:30'],
    ['2019-01-04 08:00:30','2019-01-04 10:00:30'],
    ['2019-01-04 10:00:30','2019-01-04 12:00:30'],
];

/*** Ensure performance by keeping the $timePeriods format correct ***/
// Filter $timeperiods to make sure the data is correct.
$workTimeperiods = TimePeriodHelper::filter($workTimeperiods);
// Sort out $timeperiods to make sure the content and sorting are correct.
$workTimeperiods = TimePeriodHelper::union($workTimeperiods);
// When you achieve the two operations described above, you can turn off Auto sort out (TimePeriodHelper::setSortOut(false)) to improve performance. (Global)
TimePeriodHelper::setSortOut(false);

// Set time unit (Global)
TimePeriodHelper::setUnit('minute');

// Maybe you want change time format
$workTimeperiods = TimePeriodHelper::format($workTimeperiods);

// Now value :
// $workTimeperiods = [ ['2019-01-04 08:00:00','2019-01-04 12:00:00'], ['2019-01-04 13:00:00','2019-01-04 17:00:00'] ];

// Now you can execute the function you want to execute. Like gap()
$gapTimeperiods = TimePeriodHelper::gap($workTimeperiods);
// Result: [ ['2019-01-04 12:00:00','2019-01-04 13:00:00'] ]

// Calculation time
$workTime = TimePeriodHelper::time($workTimeperiods);
// Result: 480

$gapTime = TimePeriodHelper::time($gapTimeperiods);
// Result: 60

sort(Array $timePeriods) : array

$templete = [
    ['2019-01-04 12:00:00','2019-01-04 18:00:00'],
    ['2019-01-04 08:00:00','2019-01-04 12:00:00'],
    ['2019-01-04 12:00:00','2019-01-04 18:00:00'],
    ['2019-01-04 12:00:00','2019-01-04 17:00:00'],
    ['2019-01-04 12:00:00','2019-01-04 19:00:00'],
    ['2019-01-04 08:00:00','2019-01-04 12:00:00'],
    ['2019-01-04 09:00:00','2019-01-04 12:00:00'],
    ['2019-01-04 07:00:00','2019-01-04 12:00:00'],
    ['2019-01-04 10:00:00','2019-01-04 16:00:00'],
    ['2019-01-04 11:00:00','2019-01-04 18:00:00'],
    ['2019-01-04 10:00:00','2019-01-04 18:00:00'],
    ['2019-01-04 11:00:00','2019-01-04 15:00:00']
];

$result = TimePeriodHelper::sort($templete);
//$result = [
//    ['2019-01-04 07:00:00','2019-01-04 12:00:00'],
//    ['2019-01-04 08:00:00','2019-01-04 12:00:00'],
//    ['2019-01-04 08:00:00','2019-01-04 12:00:00'],
//    ['2019-01-04 09:00:00','2019-01-04 12:00:00'],
//    ['2019-01-04 10:00:00','2019-01-04 16:00:00'],
//    ['2019-01-04 10:00:00','2019-01-04 18:00:00'],
//    ['2019-01-04 11:00:00','2019-01-04 15:00:00'],
//    ['2019-01-04 11:00:00','2019-01-04 18:00:00'],
//    ['2019-01-04 12:00:00','2019-01-04 17:00:00'],
//    ['2019-01-04 12:00:00','2019-01-04 18:00:00'],
//    ['2019-01-04 12:00:00','2019-01-04 18:00:00'],
//    ['2019-01-04 12:00:00','2019-01-04 19:00:00']
//];

TimePeriodHelper::union(Array $timePeriods1, [Array $timePeriods2, [Array $timePeriods3, ......]]) : array

$templete1 = [
    ['2019-01-04 13:00:00','2019-01-04 15:00:00'],
    ['2019-01-04 10:00:00','2019-01-04 12:00:00'],
    ['2019-01-04 19:00:00','2019-01-04 22:00:00'],
    ['2019-01-04 15:00:00','2019-01-04 18:00:00']
];

$templete2 = [
    ['2019-01-04 08:00:00','2019-01-04 09:00:00'],
    ['2019-01-04 14:00:00','2019-01-04 16:00:00'],
    ['2019-01-04 21:00:00','2019-01-04 23:00:00']
];
// Sort and merge one timeperiods
$result1 = TimePeriodHelper::union($templete1);
//$result1 = [
//    ['2019-01-04 10:00:00','2019-01-04 12:00:00'],
//    ['2019-01-04 13:00:00','2019-01-04 18:00:00'],
//    ['2019-01-04 19:00:00','2019-01-04 22:00:00']
//];

// Sort and merge two timeperiods
$result2 = TimePeriodHelper::union($templete1, $templete2);
//$result2 = [
//    ['2019-01-04 08:00:00','2019-01-04 09:00:00'],
//    ['2019-01-04 10:00:00','2019-01-04 12:00:00'],
//    ['2019-01-04 13:00:00','2019-01-04 18:00:00'],
//    ['2019-01-04 19:00:00','2019-01-04 23:00:00']
//];

diff(Array $timePeriods1, Array $timePeriods2, $sortOut = 'default') : array

$templete1 = [
    ['2019-01-04 07:20:00','2019-01-04 08:00:00'],
    ['2019-01-04 07:00:00','2019-01-04 07:20:00'],
];
$templete2 = [
    ['2019-01-04 07:30:00','2019-01-04 07:40:00'],
];

/*** Note 5. Ensure performance by keeping the $timePeriods format correct. ***/
// 1. Set Auto sorting out (Scope: Global. Default, no need to set)
//TimePeriodHelper::setSortOut(true);

// 2. Set Manually sorting out (Scope: Global) (When a lot of logic operations, it is better)
TimePeriodHelper::setSortOut(false);
$templete1 = TimePeriodHelper::union($templete1);
$templete2 = TimePeriodHelper::union($templete2);


$result = TimePeriodHelper::diff($templete1, $templete2);
//$result = [
//    ['2019-01-04 07:00:00','2019-01-04 07:30:00'],
//    ['2019-01-04 07:40:00','2019-01-04 08:00:00'],
//];

intersect(Array $timePeriods1, Array $timePeriods2, $sortOut = 'default') : array

$templete1 = [
    ['2019-01-04 07:35:00','2019-01-04 08:00:00'],
    ['2019-01-04 07:00:00','2019-01-04 07:35:00'],
];
$templete2 = [
    ['2019-01-04 07:30:00','2019-01-04 07:40:00'],
];

/*** Note 5. Ensure performance by keeping the $timePeriods format correct. ***/
// 1. Set Auto sorting out (Scope: Global. Default, no need to set)
//TimePeriodHelper::setSortOut(true);

// 2. Set Auto sorting out (Scope: Global) (When a lot of logic operations, it is better)
TimePeriodHelper::setSortOut(false);
$templete1 = TimePeriodHelper::union($templete1);
$templete2 = TimePeriodHelper::union($templete2);


$result = TimePeriodHelper::intersect($templete1, $templete2);
//$result = [
//    ['2019-01-04 07:30:00','2019-01-04 07:40:00'],
//];

isOverlap(Array $timePeriods1, Array $timePeriods2) : bool

$templete1 = [
    ['2019-01-04 07:00:00','2019-01-04 08:00:00']
];
$templete2 = [
    ['2019-01-04 07:30:00','2019-01-04 07:40:00'],
];
$result = TimePeriodHelper::isOverlap($templete1, $templete2);
// $result = true;

contact(Array $timePeriods, String $sDateTime, String $eDateTime = null, $sortOut = 'default') : Array

$templete = [
    ['2019-01-04 08:00:00','2019-01-04 12:00:00'],
    ['2019-01-04 13:00:00','2019-01-04 16:00:00'],
    ['2019-01-04 17:00:00','2019-01-04 19:00:00']
];

$result = TimePeriodHelper::contact($templete, '2019-01-04 12:00:00');
// $result = [];

$result = TimePeriodHelper::contact($templete, '2019-01-04 12:00:00', '2019-01-04 13:00:00');
// $result = [];

$result = TimePeriodHelper::contact($templete, '2019-01-04 12:00:00', '2019-01-04 14:00:00');
// $result = [['2019-01-04 13:00:00','2019-01-04 16:00:00']];

$result = TimePeriodHelper::contact($templete, '2019-01-04 13:00:00');
// $result = [['2019-01-04 13:00:00','2019-01-04 16:00:00']];

$result = TimePeriodHelper::contact($templete, '2019-01-04 13:00:00', '2019-01-04 14:00:00');
// $result = [['2019-01-04 13:00:00','2019-01-04 16:00:00']];

$result = TimePeriodHelper::contact($templete, '2019-01-04 13:30:00');
// $result = [['2019-01-04 13:00:00','2019-01-04 16:00:00']];

$result = TimePeriodHelper::contact($templete, '2019-01-04 13:30:00', '2019-01-04 18:00:00');
// $result = [['2019-01-04 13:00:00','2019-01-04 16:00:00'], ['2019-01-04 17:00:00','2019-01-04 19:00:00']];

$result = TimePeriodHelper::contact($templete, '2019-01-04 13:30:00', '2019-01-04 22:00:00');
// $result = [['2019-01-04 13:00:00','2019-01-04 16:00:00'], ['2019-01-04 17:00:00','2019-01-04 19:00:00']];

greaterThan(Array $timePeriods, $refDatetime, $fullTimePeriod = true, $sortOut = 'default') : Array

$templete = [
    ['2019-01-04 08:00:00','2019-01-04 12:00:00'],
    ['2019-01-04 13:00:00','2019-01-04 16:00:00'],
    ['2019-01-04 17:00:00','2019-01-04 19:00:00']
];

$result = TimePeriodHelper::greaterThan($templete, '2019-01-04 13:00:00', false);
// $result = [['2019-01-04 13:00:00','2019-01-04 16:00:00'], ['2019-01-04 17:00:00','2019-01-04 19:00:00']];

$result = TimePeriodHelper::greaterThan($templete, '2019-01-04 14:00:00', false);
// $result = [['2019-01-04 13:00:00','2019-01-04 16:00:00'], ['2019-01-04 17:00:00','2019-01-04 19:00:00']];

$result = TimePeriodHelper::greaterThan($templete, '2019-01-04 16:00:00', false);
// $result = [['2019-01-04 17:00:00','2019-01-04 19:00:00']];

$result = TimePeriodHelper::greaterThan($templete, '2019-01-04 13:00:00', true);
// $result = [['2019-01-04 13:00:00','2019-01-04 16:00:00'], ['2019-01-04 17:00:00','2019-01-04 19:00:00']];

$result = TimePeriodHelper::greaterThan($templete, '2019-01-04 14:00:00', true);
// $result = [['2019-01-04 17:00:00','2019-01-04 19:00:00']];

$result = TimePeriodHelper::greaterThan($templete, '2019-01-04 16:00:00', true);
// $result = [['2019-01-04 17:00:00','2019-01-04 19:00:00']];

$result = TimePeriodHelper::greaterThan($templete, '2019-01-04 14:00:00');
// $result = [['2019-01-04 17:00:00','2019-01-04 19:00:00']];

lessThan(Array $timePeriods, $refDatetime, $fullTimePeriod = true, $sortOut = 'default') : Array

$templete = [
    ['2019-01-04 08:00:00','2019-01-04 12:00:00'],
    ['2019-01-04 13:00:00','2019-01-04 16:00:00'],
    ['2019-01-04 17:00:00','2019-01-04 19:00:00']
];

$result = TimePeriodHelper::lessThan($templete, '2019-01-04 13:00:00', false);
// $result = ['2019-01-04 08:00:00','2019-01-04 12:00:00']];

$result = TimePeriodHelper::lessThan($templete, '2019-01-04 14:00:00', false);
// $result = [['2019-01-04 08:00:00','2019-01-04 12:00:00'], ['2019-01-04 13:00:00','2019-01-04 16:00:00']];

$result = TimePeriodHelper::lessThan($templete, '2019-01-04 16:00:00', false);
// $result = [['2019-01-04 08:00:00','2019-01-04 12:00:00'], ['2019-01-04 13:00:00','2019-01-04 16:00:00']];

$result = TimePeriodHelper::lessThan($templete, '2019-01-04 13:00:00', true);
// $result = ['2019-01-04 08:00:00','2019-01-04 12:00:00']];

$result = TimePeriodHelper::lessThan($templete, '2019-01-04 14:00:00', true);
// $result = ['2019-01-04 08:00:00','2019-01-04 12:00:00']];

$result = TimePeriodHelper::lessThan($templete, '2019-01-04 16:00:00', true);
// $result = [['2019-01-04 08:00:00','2019-01-04 12:00:00'], ['2019-01-04 13:00:00','2019-01-04 16:00:00']];

$result = TimePeriodHelper::lessThan($templete, '2019-01-04 14:00:00');
// $result = ['2019-01-04 08:00:00','2019-01-04 12:00:00']];

fill(Array $timePeriods) : array

$templete = [
    ['2019-01-04 08:00:00','2019-01-04 12:00:00'],
    ['2019-01-04 10:00:00','2019-01-04 19:00:00'],
    ['2019-01-04 12:00:00','2019-01-04 18:00:00']
];

$result = TimePeriodHelper::fill($templete);
//$result = [
//    ['2019-01-04 08:00:00','2019-01-04 19:00:00'],
//];

gap(Array $timePeriods, $sortOut = 'default') : array

$templete = [
    ['2019-01-04 08:00:00','2019-01-04 12:00:00'],
    ['2019-01-04 04:00:00','2019-01-04 05:00:00'],
    ['2019-01-04 07:00:00','2019-01-04 09:00:00'],
    ['2019-01-04 13:00:00','2019-01-04 18:00:00']
];

/*** Note 5. Ensure performance by keeping the $timePeriods format correct. ***/
// 1. Set Auto sorting out (Scope: Global. Default, no need to set)
//TimePeriodHelper::setSortOut(true);

// 2. Set Manually sorting out (Scope: Global) (When a lot of logic operations, it is better)
TimePeriodHelper::setSortOut(false);
$templete = TimePeriodHelper::union($templete);


$result = TimePeriodHelper::gap($templete);
//$result = [
//    ['2019-01-04 05:00:00','2019-01-04 07:00:00'],
//    ['2019-01-04 12:00:00','2019-01-04 13:00:00'],
//];

time(Array $timePeriods, Int $precision = 0, $sortOut = 'default') : array

$templete = [
    ['2019-01-04 08:00:00','2019-01-04 12:00:00'],
    ['2019-01-04 04:00:00','2019-01-04 05:00:00'],
    ['2019-01-04 07:00:00','2019-01-04 09:00:00'],
    ['2019-01-04 13:00:00','2019-01-04 18:30:30']
];

/*** Note 5. Ensure performance by keeping the $timePeriods format correct. ***/
// 1. Set Auto sorting out (Scope: Global. Default, no need to set)
//TimePeriodHelper::setSortOut(true);

// 2. Set Manually sorting out (Scope: Global) (When a lot of logic operations, it is better)
TimePeriodHelper::setSortOut(false);
$templete= TimePeriodHelper::union($templete);


TimePeriodHelper::setUnit('hour');
$resultH1 = TimePeriodHelper::time($templete);
// $resultH = 11;

$resultH2 = TimePeriodHelper::time($templete, 4);
// $resultH = 11.5083;

$resultM = TimePeriodHelper::setUnit('minutes')->time($templete, 2);
// $resultM = 690.5;

TimePeriodHelper::setUnit('s');
$resultS = TimePeriodHelper::time($templete);
// $resultS = 41430;

cut(Array $timePeriods, Int $time, $sortOut = 'default') : array

$templete = [
    ['2019-01-04 08:20:00','2019-01-04 12:00:00'],
    ['2019-01-04 08:00:00','2019-01-04 08:25:00']
];

/*** Note 5. Ensure performance by keeping the $timePeriods format correct. ***/
// 1. Set Auto sorting out (Scope: Global. Default, no need to set)
//TimePeriodHelper::setSortOut(true);

// 2. Set Manually sorting out (Scope: Global) (When a lot of logic operations, it is better)
TimePeriodHelper::setSortOut(false);
$templete = TimePeriodHelper::union($templete);


$resultM = TimePeriodHelper::setUnit('minutes')->cut($templete, '30');
// $resultM = [
//     ['2019-01-04 08:00:00','2019-01-04 08:30:00']
// ];

TimePeriodHelper::setUnit('hour');
$resultH1 = TimePeriodHelper::cut($templete, '30');
// $resultH1 = [
//     ['2019-01-04 08:00:00','2019-01-04 12:00:00']
// ];


extend(Array $timePeriods, Int $time, $interval = 0, $sortOut = 'default') : array

$templete = [
    ['2019-01-04 08:20:00','2019-01-04 12:00:00'],
    ['2019-01-04 08:00:00','2019-01-04 08:25:00'],
];

/*** Note 5. Ensure performance by keeping the $timePeriods format correct. ***/
// 1. Set Auto sorting out (Scope: Global. Default, no need to set)
//TimePeriodHelper::setSortOut(true);

// 2. Set Manually sorting out (Scope: Global) (When a lot of logic operations, it is better)
TimePeriodHelper::setSortOut(false);
$templete = TimePeriodHelper::union($templete);


$resultM1 = TimePeriodHelper::setUnit('minutes')->extend($templete, 30, 0);
// $resultM1 = [
//     ['2019-01-04 08:00:00','2019-01-04 12:30:00']
// ];

$resultM2 = TimePeriodHelper::setUnit('minutes')->extend($templete, 30, 40);
// $resultM2 = [
//     ['2019-01-04 08:00:00','2019-01-04 12:00:00'], ['2019-01-04 12:40:00','2019-01-04 13:10:00']
// ];

TimePeriodHelper::setUnit('hour');
$resultH1 = TimePeriodHelper::extend($templete, 2, 0);
// $resultH1 = [
//     ['2019-01-04 08:00:00','2019-01-04 14:00:00']
// ];

$resultH2 = TimePeriodHelper::setUnit('hour')->extend($templete, 2, 1);
// $resultH2 = [
//     ['2019-01-04 08:00:00','2019-01-04 12:00:00'], ['2019-01-04 13:00:00','2019-01-04 15:00:00']
// ];

shorten(Array $timePeriods, Int $time, $crossperiod = true, $sortOut = 'default') : array

$templete = [
    ['2019-01-04 13:00:00','2019-01-04 15:00:00'],
    ['2019-01-04 08:20:00','2019-01-04 12:00:00'],
    ['2019-01-04 08:00:00','2019-01-04 08:25:00'],
];

/*** Note 5. Ensure performance by keeping the $timePeriods format correct. ***/
// 1. Set Auto sorting out (Scope: Global. Default, no need to set)
//TimePeriodHelper::setSortOut(true);

// 2. Set Manually sorting out (Scope: Global) (When a lot of logic operations, it is better)
TimePeriodHelper::setSortOut(false);
$templete = TimePeriodHelper::union($templete);


TimePeriodHelper::setUnit('minutes');
$resultM1 = TimePeriodHelper::shorten($templete, 30, true);
// $resultM1 = [
//     ['2019-01-04 08:00:00','2019-01-04 12:00:00'], ['2019-01-04 13:00:00','2019-01-04 14:30:00']
// ];

$resultH1 = TimePeriodHelper::setUnit('hour')->shorten($templete, 1, true);
// $resultH1 = [
//     ['2019-01-04 08:00:00','2019-01-04 12:00:00'], ['2019-01-04 13:00:00','2019-01-04 14:00:00']
// ];

$resultH2 = TimePeriodHelper::setUnit('hour')->shorten($templete, 2, true);
// $resultH2 = [
//     ['2019-01-04 08:00:00','2019-01-04 12:00:00']
// ];


$resultH3 = TimePeriodHelper::setUnit('hour')->shorten($templete, 5, true);
// $resultH3 = [
//     ['2019-01-04 08:00:00','2019-01-04 09:00:00']
// ];

$resultH4 = TimePeriodHelper::setUnit('hour')->shorten($templete, 10, true);
// $resultH4 = [];

$resultH5 = TimePeriodHelper::setUnit('hour')->shorten($templete, 1, false);
// $resultH5 = [
//     ['2019-01-04 08:00:00','2019-01-04 12:00:00'], ['2019-01-04 13:00:00','2019-01-04 14:00:00']
// ];

$resultH6 = TimePeriodHelper::setUnit('hour')->shorten($templete, 2, false);
// $resultH6 = [
//     ['2019-01-04 08:00:00','2019-01-04 12:00:00']
// ];

$resultH7 = TimePeriodHelper::setUnit('hour')->shorten($templete, 5, false);
// $resultH7 = [
//     ['2019-01-04 08:00:00','2019-01-04 12:00:00']
// ];

$resultH8 = TimePeriodHelper::setUnit('hour')->shorten($templete, 10, false);
// $resultH8 = [
//     ['2019-01-04 08:00:00','2019-01-04 12:00:00']
// ];

format(Array $timePeriods, $unit = 'default') : array

$templete = [
    ['2019-01-04 08:11:11','2019-01-04 12:22:22'],
    ['2019-01-04 04:33:33','2019-01-04 05:44:44'],
    ['2019-01-04 05:55','2019-01-04 06:55'],
    ['2019-01-04 07','2019-01-04 08'],
];

// Set time uint
TimePeriodHelper::setUnit('minute');

// Convert format
$result = TimePeriodHelper::format($templete);
//$result = [
//    ['2019-01-04 08:11:00','2019-01-04 12:22:00'],
//    ['2019-01-04 04:33:00','2019-01-04 05:44:00'],
//    ['2019-01-04 05:55:00','2019-01-04 06:55:00'],
//    ['2019-01-04 07:00:00','2019-01-04 08:00:00'],
//];

validate(Array $timePeriods) : Exception | true

$templete = [
    ['2019-01-04 02:00:00','2019-01-04 03:00:00'],
    ['2019-01-04 08:00:00','2019-01-04 12:00:00','2019-01-04 12:00:00'],
    ['2019-01-04 04:00:00'],
    ['2019-01-04 04:00','2019-01-04 05:00:00'],
    'string',
    ['2019-01-04 08:00:00','2019-01-04 05:00:00'],
    ['2019-01-04 19:00:00','2019-01-04 19:00:00'],
];

try {
    $result = TimePeriodHelper::validate($templete);
} catch (\Exception $e) {
    $result = false;
}
//$result = false;

filter(Array $timePeriods) : array

$templete = [
    ['2019-01-04 02:00:00','2019-01-04 03:00:00'],
    ['2019-01-04 08:00:00','2019-01-04 12:00:00','2019-01-04 12:00:00'],
    ['2019-01-04 04:00:00'],
    ['2019-01-04 04:00','2019-01-04 05:00:00'],
    'string',
    ['2019-01-04 08:00:00','2019-01-04 05:00:00'],
    ['2019-01-04 19:00:00','2019-01-04 19:00:00'],
    ['2019-01-04 24:00:00','2019-01-05 24:00:00'],
];

// Set whether need to filter the datetime
//TimePeriodHelper::setFilterDatetime(false);

// Filter time period
$result = TimePeriodHelper::filter($templete);
//$result = [
//    ['2019-01-04 02:00:00','2019-01-04 03:00:00'],
//    ['2019-01-05 00:00:00','2019-01-06 00:00:00'],
//];

setUnit(string $unit, string $target = 'all') : self

// Set unit hour for all
TimePeriodHelper::setUnit('hour');
// Set unit hour for format
TimePeriodHelper::setUnit('minute', 'format');

// Get unit
$result1 = TimePeriodHelper::getUnit('time');
//$result1 = 'hour';

$result2 = TimePeriodHelper::getUnit('format');
//$result2 = 'minute';

getUnit(string $target) : string

// Set unit hour for all
TimePeriodHelper::setUnit('hour');
// Set unit hour for format
TimePeriodHelper::setUnit('minute', 'format');

// Get unit
$result1 = TimePeriodHelper::getUnit('time');
//$result1 = 'hour';

$result2 = TimePeriodHelper::getUnit('format');
//$result2 = 'minute';

setFilterDatetime(Bool $bool) : self

TimePeriodHelper::setFilterDatetime(false);
$result1 = TimePeriodHelper::getFilterDatetime();
//$result1 = false;

TimePeriodHelper::setFilterDatetime(true);
$result2 = TimePeriodHelper::getFilterDatetime();
//$result1 = true;

getFilterDatetime() : bool

TimePeriodHelper::setFilterDatetime(false);
$result1 = TimePeriodHelper::getFilterDatetime();
//$result1 = false;

TimePeriodHelper::setFilterDatetime(true);
$result2 = TimePeriodHelper::getFilterDatetime();
//$result1 = true;

setSortOut(bool $bool = true) : self

TimePeriodHelper::setSortOut(false);
$result1 = TimePeriodHelper::getSortOut();
//$result1 = false;

TimePeriodHelper::setSortOut(true);
$result2 = TimePeriodHelper::getSortOut();
//$result1 = true;

getSortOut() : bool

TimePeriodHelper::setSortOut(false);
$result1 = TimePeriodHelper::getSortOut();
//$result1 = false;

TimePeriodHelper::setSortOut(true);
$result2 = TimePeriodHelper::getSortOut();
//$result1 = true;

isDatetime(string $datetime) : bool

$result = TimePeriodHelper::isDatetime('2019-01-04 08:00:00');
// $result = true;

$result = TimePeriodHelper::isDatetime('2019-01-04 88:88:88');
// $result = true;

$result = TimePeriodHelper::isDatetime('2019-01-04 08:00');
// $result = false;

 timeFormatConv(string $datetime, $unit = 'default') : string

$result = TimePeriodHelper::timeFormatConv('2019-01-04 08:33:33');
// $result = '2019-01-04 08:33:33';

$result = TimePeriodHelper::timeFormatConv('2019-01-04 08:33:33', 'default');
// $result = '2019-01-04 08:33:33';

$result = TimePeriodHelper::timeFormatConv('2019-01-04 08:33:33', 'second');
// $result = '2019-01-04 08:33:33';

$result = TimePeriodHelper::timeFormatConv('2019-01-04 08:33:33', 'minute');
// $result = '2019-01-04 08:33:00';

$result = TimePeriodHelper::timeFormatConv('2019-01-04 08:33:33', 'hour');
// $result = '2019-01-04 08:00:00';

$result = TimePeriodHelper::timeFormatConv('2019-01-04 08');
// $result = '2019-01-04 08:00:00';

$result = TimePeriodHelper::timeFormatConv('2019-01-04 08', 'default');
// $result = '2019-01-04 08:00:00';

$result = TimePeriodHelper::timeFormatConv('2019-01-04 08', 'default');
// $result = '2019-01-04 08:00:00';

$result = TimePeriodHelper::timeFormatConv('2019-01-04 08', 'default');
// $result = '2019-01-04 08:00:00';

$result = TimePeriodHelper::timeFormatConv('2019-01-04 08', 'default');
// $result = '2019-01-04 08:00:00';

time2Second($time, $unit = 'default') : number

$result = TimePeriodHelper::time2Second(30);
// $result = 30;

$result = TimePeriodHelper::time2Second(30, 'default');
// $result = 30;

$result = TimePeriodHelper::time2Second(30, 'second');
// $result = 30;

$result = TimePeriodHelper::time2Second(30, 'minute');
// $result = 1800;

$result = TimePeriodHelper::time2Second(30, 'hour');
// $result = 108000;