Created
June 25, 2020 07:32
-
-
Save designhash/ef635059c17422953fe925246ba5792c to your computer and use it in GitHub Desktop.
Display Name on assigned week php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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