Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save designhash/ef635059c17422953fe925246ba5792c to your computer and use it in GitHub Desktop.
Save designhash/ef635059c17422953fe925246ba5792c to your computer and use it in GitHub Desktop.
Display Name on assigned week php
// add as much ppeople as you like
$people = array('Ana', 'Bobby', 'Charlie', 'Darren', 'Emma');
// Here you can add holidays
//$holidays = array('2012-07-12', '2012-07-7');
$holidays = array('');
//set start time once
$start = new DateTime('2020-01-06');
// Because the end date need to be + 1(bug?)
$start->modify('+1 day');
// set date today
$end = new DateTime('2015-07-13');
// otherwise the end date is excluded (bug?)
$end->modify('+1 day');
// total days
$interval = $end->diff($start);
$days = $interval->days;
// create an iterateable period of date (P1D equates to 1 day)
$period = new DatePeriod($start, new DateInterval('P1D'), $end);
foreach($period as $dt) {
$curr = $dt->format('D');
// for the updated question
if (in_array($dt->format('Y-m-d'), $holidays)) {
$days--;
}
// substract if Saturday or Sunday
if ($curr == 'Sat' || $curr == 'Sun') {
$days--;
}
}
$days = $days % count($people);
echo $people[$days] . " will display the contact";
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment