note 77964 added to function.time

From: Date: Fri, 21 Sep 2007 16:30:11 +0000
Subject: note 77964 added to function.time
Groups: php.notes 
Request: Send a blank email to php-notes+get-130672@lists.php.net to get a copy of this message
Fire Fighters typically work one day on and two days off. Known as shifts and generally referred to as A, B and C. I need to compute this for a web script so I came up with the following function. Notes: You may need to change the reference date as not all departments are on the same rotation. Also, this does not take into account daylight savings time so the changeover moves by an hour. <?php function whatShift() { $referencePoint = mktime(7, 0, 0, 9, 11, 2004); // Sept 11, 2004 at 7AM started an A Shift. $now = time(); // Next we need to know how many seconds since the start of the last A Shift. // First we compute how many 3 days cycles since the reference point then // subtract that number. $difference = ($now - $referencePoint); $cycles = floor($difference / (60 * 60 * 24 * 3)); $sinceReference = ($difference - ($cycles * 60 * 60 * 24 * 3)); if ($sinceReference < 60 * 60 * 25) { // Before the start of the 25th hour it's A Shift. $shift = "A"; } elseif ($sinceReference < 60 * 60 * 49) { // Else before the start of the 49th hour it's B Shift. $shift = "B"; } else { $shift = "C"; // Else it's C Shift. } return $shift; } ?> ---- Server IP: 208.69.120.35 Probable Submitter: 69.140.221.147 ---- Manual Page -- http://www.php.net/manual/en/function.time.php Edit -- https://master.php.net/note/edit/77964 Del: integrated -- https://master.php.net/note/delete/77964/integrated Del: useless -- https://master.php.net/note/delete/77964/useless Del: bad code -- https://master.php.net/note/delete/77964/bad+code Del: spam -- https://master.php.net/note/delete/77964/spam Del: non-english -- https://master.php.net/note/delete/77964/non-english Del: in docs -- https://master.php.net/note/delete/77964/in+docs Del: other reasons-- https://master.php.net/note/delete/77964 Reject -- https://master.php.net/note/reject/77964 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#130672) next »