note 87283 deleted from function.date by derick
| From: | derick@php.net | Date: | Sun, 22 Mar 2009 18:45:26 +0000 |
| Subject: | note 87283 deleted from function.date by derick | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-152299@lists.php.net to get a copy of this message | ||
Note Submitter: Anonymous
----
Reverse of getWorkingDays() function.
<?php
function getTargetWorkingDate($startDate, $days, $holidays = null) {
$the_first_day_of_week = date("N",strtotime($startDate));
if($the_first_day_of_week == 6) $b_extra+=2;
if($the_first_day_of_week == 7) $b_extra++;
$startDate = getdate((($b_extra) * 86400) + strtotime($startDate));
$startDate = $startDate['year'] . "-" . $startDate['mon'] .
"-" . $startDate['mday'];
$no_weeks = floor($days / 5);
$extra_days = $no_weeks * 2;
$endDate = getdate((($days+$extra_days) * 86400) + strtotime($startDate));
$endDate = $endDate['year'] . "-" . $endDate['mon'] .
"-" . $endDate['mday'];
if($holidays) {
foreach($holidays as $holiday){
$time_stamp = strtotime($holiday);
if (strtotime($startDate) <= $time_stamp && $time_stamp <= strtotime($endDate)
&& date("N",$time_stamp) != 6 && date("N",$time_stamp) != 7)
$extra_days++;
}
}
$endDate = getdate((($days+$extra_days) * 86400) + strtotime($startDate));
$endDate = $endDate['year'] . "-" . $endDate['mon'] .
"-" . $endDate['mday'];
$the_last_day_of_week = date("N",strtotime($endDate));
if($the_last_day_of_week == 6) $e_extra+=2;
if($the_last_day_of_week == 7) $e_extra++;
$endDate = getdate((($e_extra) * 86400) + strtotime($endDate));
$endDate = $endDate['year'] . "-" . $endDate['mon'] .
"-" . $endDate['mday'];
return $endDate;
}
?>