| Server IP : 47.82.179.145 / Your IP : 216.73.217.129 Web Server : nginx/1.26.3 System : Linux iZt4n9czhka2zvqfajdlr2Z 6.8.0-63-generic #66-Ubuntu SMP PREEMPT_DYNAMIC Fri Jun 13 20:25:30 UTC 2025 x86_64 User : www ( 1001) PHP Version : 8.3.30 Disable Function : passthru,exec,system,putenv,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /www/wwwroot/scuipturepactory.com/wp-content/plugins.off/latepoint/lib/misc/ |
Upload File : |
<?php
/*
* Copyright (c) 2022 LatePoint LLC. All rights reserved.
*/
namespace LatePoint\Misc;
class TimePeriod{
public int $start_time = 0;
public int $end_time = 0;
function __construct($args = []){
$allowed_props = self::allowed_props();
foreach($args as $key => $arg){
if(in_array($key, $allowed_props)) $this->$key = $arg;
}
}
public static function merge_periods(array $time_periods): array{
if(!$time_periods) return [];
$result = [$time_periods[0]];
for ($i = 0; $i < count($time_periods); $i++) {
$x1 = $time_periods[$i]->start_time;
$y1 = $time_periods[$i]->end_time;
$x2 = $result[count($result) - 1]->start_time;
$y2 = $result[count($result) - 1]->end_time;
if ($y2 >= $x1) {
$result[count($result) - 1]->end_time = max($y1, $y2);
} else {
$result[] = new TimePeriod(['start_time' => $x1, 'end_time' => $y1]);
}
}
return $result;
}
public static function create_from_work_period(WorkPeriod $work_period){
return new TimePeriod(['start_time' => $work_period->start_time, 'end_time' => $work_period->end_time]);
}
/**
* @param array $overlapped_time_periods
* @return TimePeriod
*/
public static function get_unified_period_from_overlapped_periods(array $overlapped_time_periods): TimePeriod{
$bounds = [];
foreach($overlapped_time_periods as $time_period){
$bounds[] = $time_period->start_time;
$bounds[] = $time_period->end_time;
}
return new TimePeriod(['start_time' => min($bounds), 'end_time' => max($bounds)]);
}
public function check_if_overlaps(TimePeriod $check_time_period){
return (($this->start_time < $check_time_period->end_time) && ($check_time_period->start_time < $this->end_time));
}
public static function allowed_props(): array{
return ['start_time',
'end_time'];
}
}