initial commit
This commit is contained in:
parent
aac4b251d4
commit
1276cd8fa3
|
|
@ -0,0 +1,20 @@
|
||||||
|
<?PHP
|
||||||
|
$conf = [
|
||||||
|
'shifts' => array('A','B','C'), //Crew designators in order starting at EPOCH
|
||||||
|
'timeZone' => 'America/New_York', //Local Time Zone
|
||||||
|
'startTime' => '07:30' //Shift start time in 24-hour format
|
||||||
|
];
|
||||||
|
|
||||||
|
//***********************************************************************************
|
||||||
|
|
||||||
|
require 'shiftCycle.php';
|
||||||
|
|
||||||
|
$shiftCycle = new shiftCycle($conf);
|
||||||
|
|
||||||
|
echo "Local Timestamp: " . $shiftCycle->timestamp . "<br/>";
|
||||||
|
echo "Whole days since EPOCH: " . $shiftCycle->daysSince . "<br/>";
|
||||||
|
echo "Cycles since EPOCH: " . $shiftCycle->cyclesSince . "<br/>";
|
||||||
|
echo "Day in cycle: " . ($shiftCycle->cyclePart + 1) . "<br/>";
|
||||||
|
echo "Crew on duty: " . $shiftCycle->currentShift . "<br/>";
|
||||||
|
|
||||||
|
?>
|
||||||
|
|
@ -0,0 +1,34 @@
|
||||||
|
<?PHP
|
||||||
|
class shiftCycle {
|
||||||
|
|
||||||
|
public $timestamp;
|
||||||
|
public $daysSince;
|
||||||
|
public $cyclesSince;
|
||||||
|
public $cyclePart;
|
||||||
|
public $currentShift;
|
||||||
|
|
||||||
|
function __construct($conf){
|
||||||
|
|
||||||
|
$dtz = new DateTimeZone($conf['timeZone']);
|
||||||
|
$dt = new DateTime('now', $dtz); //DateTime object set to defined TZ
|
||||||
|
$this->timestamp = $dt->format('U');
|
||||||
|
|
||||||
|
$adj = ($this->timestamp - ($this->timeToSeconds($conf['startTime']))); //align shift start change to midnight.
|
||||||
|
$this->daysSince = floor($adj / 86400); //Whole days since EPOCH
|
||||||
|
$this->cyclesSince = floor(($this->daysSince / 3)*10)/10; //Cycles since EPOCH
|
||||||
|
$this->cyclePart = floor(((($this->cyclesSince - floor($this->cyclesSince)) * 10) / count($conf['shifts']))); //Day in cycle
|
||||||
|
$this->currentShift = $conf['shifts'][$this->cyclePart]; //Current Shift
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private function timeToSeconds($time){ // returns 24-hour time into seconds since midnight
|
||||||
|
|
||||||
|
$hm1 = explode(':', $time); // split hours and minutes
|
||||||
|
$hm2 = $hm1[0] + round($hm1[1] / 60, 2); // determine number of hours since midnight
|
||||||
|
$hm3 = $hm2 * 3600; // convert hours to seconds
|
||||||
|
|
||||||
|
return $hm3;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
||||||
Loading…
Reference in New Issue