From 1276cd8fa390ad6febe57378e103aab3da975fab Mon Sep 17 00:00:00 2001 From: Eric Fawcett Date: Sat, 24 Oct 2020 16:45:07 -0400 Subject: [PATCH] initial commit --- demo.php | 20 ++++++++++++++++++++ shiftCycle.php | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 demo.php create mode 100644 shiftCycle.php diff --git a/demo.php b/demo.php new file mode 100644 index 0000000..144b055 --- /dev/null +++ b/demo.php @@ -0,0 +1,20 @@ + 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 . "
"; +echo "Whole days since EPOCH: " . $shiftCycle->daysSince . "
"; +echo "Cycles since EPOCH: " . $shiftCycle->cyclesSince . "
"; +echo "Day in cycle: " . ($shiftCycle->cyclePart + 1) . "
"; +echo "Crew on duty: " . $shiftCycle->currentShift . "
"; + +?> \ No newline at end of file diff --git a/shiftCycle.php b/shiftCycle.php new file mode 100644 index 0000000..7742f82 --- /dev/null +++ b/shiftCycle.php @@ -0,0 +1,34 @@ +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; + + } +} +?> \ No newline at end of file