time - Calculating date difference when working with a set of business hours in PHP -


i'm working on desk app. users create tickets, , i'm trying figure out how code due time.

say have business hours array looks this:

$bh['monday']['start_time'] = "8:00am" $bh['monday']['end_time'] = "5:00pm" $bh['tuesday']['start_time'] = "8:00am" $bh['tuesday']['end_time'] = "5:00pm" $bh['wednesday']['start_time'] = "8:00am" $bh['wednesday']['end_time'] = "5:00pm" $bh['thursday']['start_time'] = "8:00am" $bh['thursday']['end_time'] = "5:00pm" $bh['friday']['start_time'] = "8:00am" $bh['friday']['end_time'] = "5:00pm" 

and array holidays:

$holidays = array("dec 25th","nov 24th") 

i have 2 other variables:

$resolve_within = "5"; $resolve_within_duration = "days"; 

what have far:

$resolve_within = "5"; $resolve_within_duration = "days"; $holidays = array("dec 25th","nov 24th")  $bh['monday']['start_time'] = "8:00am" $bh['monday']['end_time'] = "5:00pm" $bh['tuesday']['start_time'] = "8:00am" $bh['tuesday']['end_time'] = "5:00pm" $bh['wednesday']['start_time'] = "8:00am" $bh['wednesday']['end_time'] = "5:00pm" $bh['thursday']['start_time'] = "8:00am" $bh['thursday']['end_time'] = "5:00pm" $bh['friday']['start_time'] = "5:00pm" $bh['friday']['end_time'] = "5:00pm"   $start = new datetime('now'); //when ticket created $end = new datetime('now'); $end->modify('+'.$resolve_within.' '.$resolve_within_duration); //this due time, adding 5 days 'now'   $interval = $end->diff($start);  // total days $days = $interval->days;  // create iterateable period of date (p1d equates 1 day) $period = new dateperiod($start, new dateinterval('p1d'), $end);  foreach($period $dt) {     $curr = $dt->format('d');      //adjust days holidays     if (in_array($dt->format('m js'), $holidays)) {        $days--;     } }  echo "ticket due in $days days."; 

so, given start date , end date, how can come due time, excluding dates in $holidays array, , taking account times , days in $bh (business hours) array?

for example, if creats ticket on wed 8/23/16 @ 3:00pm, , there's holiday on friday. due time should thursday 8/11/16 @ 3:pm. keeping in mind duration can hours , not days.

for example, tickets tagged urgent, therefore $resolve_within value might "4" , $resolve_within_duration "hours"


Comments