<?php
echo getSquadRotation("2014-01-17");
function getSquadRotation($inDate)
{
//Set timezone:
date_default_timezone_set('America/New_York');
//$inDate = "2014-01-17"; //test date
$content = explode('-', $inDate);
$inDate = mktime(0, 0, 0, $content[1], $content[2], $content[0]);
$seedTime = mktime(0, 0, 0, 12, 23, 2013); //Seed timestamp
//Seed date (12/23/2013) A squad started on a Monday; let's see if this week is "Week1" or "Week2":
//Week 1: Mon: A / Tues: A / Wed: B / Thurs: B / Fri: A / Sat: A / Sun: A
//Week 2: Mon: B / Tues: B / Wed: A / Thurs: A / Fri: B / Sat: B / Sun: B
//First, let's get the Monday of current week:
//What day is today?
$today = strftime("%u", $inDate);
//"$today" is now 1-7 (Mon. - Sun.).
//If "$today" is greater than 1, we want the Unix timestamp for 1:
if ($today > 1) {
//adjust time to get to Monday's timestamp
$todayStamp = nightStartTimeStamp($inDate);
//Unix timestamp for this week starting Monday:
$currentWeekStartDay = $todayStamp - (($today - 1) * 86400);
} else {
//It's Monday, so Unix timestamp for today:
$todayStamp = nightStartTimeStamp($inDate);
$currentWeekStartDay = $todayStamp;
}
//difference between current week and seed week in weeks:
$weekDifference = ($currentWeekStartDay - $seedTime)/604800.0;
//floor() doesn't seem to be able to work and play well with others here:
$weekDifference = substr($weekDifference, 0, 1);
//create weekBlock var:
$weekBlock = 0;
if ($weekDifference % 2 == 0) {
//Weekblock 1
$weekBlock = 1;
} else {
//difference in number of weeks is odd, so we're using weekblock 2
$weekBlock = 2;
}
//workblock is figured out; let's get our "weekstart" back on track
$currentWeekStartDay -= 43200;
//abstract YYYY-MM-DD from timestamp of starting monday date of work week
$startDay = strftime("%e", $currentWeekStartDay);
$startMonth = date("n", $currentWeekStartDay);
$startYear = strftime("%Y", $currentWeekStartDay);
//get current work week dates
$monday = mktime(0, 0, 0, $startMonth, $startDay, $startYear);
$tuesday = mktime(24, 0, 0, $startMonth, $startDay, $startYear);
$wednesday = mktime(48, 0, 0, $startMonth, $startDay, $startYear);
$thursday = mktime(72, 0, 0, $startMonth, $startDay, $startYear);
$friday = mktime(96, 0, 0, $startMonth, $startDay, $startYear);
$saturday = mktime(120, 0, 0, $startMonth, $startDay, $startYear);
$sunday = mktime(144, 0, 0, $startMonth, $startDay, $startYear);
//SQUAD ROTATION (FIXED)
//Week 1: Mon: A / Tues: A / Wed: B / Thurs: B / Fri: A / Sat: A / Sun: A
//Week 2: Mon: B / Tues: B / Wed: A / Thurs: A / Fri: B / Sat: B / Sun: B
if($weekBlock == 1)
$weekRotation = array($monday=>'A', $tuesday=>'A', $wednesday=>'B', $thursday=>'B', $friday=>'A', $saturday=>'A', $sunday=>'A');
if($weekBlock == 2)
$weekRotation = array($monday=>'B', $tuesday=>'B', $wednesday=>'A', $thursday=>'A', $friday=>'B', $saturday=>'B', $sunday=>'B');
$workingSquad = null;
foreach($weekRotation as $date=>$squad)
{
if($date == $inDate)
$workingSquad = $squad;
}
if($workingSquad != null)
return $workingSquad;
}//end getSquadRotation() function
?>
Deprecated: Function strftime() is deprecated in /in/1bC2f on line 23
Fatal error: Uncaught Error: Call to undefined function nightStartTimeStamp() in /in/1bC2f:29
Stack trace:
#0 /in/1bC2f(4): getSquadRotation(1389934800)
#1 {main}
thrown in /in/1bC2f on line 29
Process exited with code 255.
Fatal error: Uncaught Error: Call to undefined function nightStartTimeStamp() in /in/1bC2f:29
Stack trace:
#0 /in/1bC2f(4): getSquadRotation(1389934800)
#1 {main}
thrown in /in/1bC2f on line 29
Process exited with code 255.