PHP Code:
function getWorkingDate($daysInAdvance){
$today=date('d-m-Y');
$originalTime=strtotime("+$daysInAdvance days", strtotime($today));
$currentTime=$originalTime;
while (date('w', $currentTime)==0 || date('w', $currentTime)==6){
$currentTime=strtotime("+1 days", $currentTime);
}
$currentWeek=date('W', time());
$currentYear=date('Y', time());
$weekInfuture=date('W', $currentTime);
$yearInfuture=date('Y', $currentTime);
if(($yearInfuture-$currentYear)==0){
if ($weekInfuture>$currentWeek)
$daysToGoFWD=2*($weekInfuture-$currentWeek);
else
$daysToGoFWD=2*((date('W', strtotime(date('24-12-'.$currentYear)))+1)-$currentWeek);
}else {
$enofTheYear=date('W', strtotime(date('31-12-'.$currentYear)))=='01'?date('W', strtotime(date('24-12-'.$currentYear))):date('W', strtotime(date('31-12-'.$currentYear)));
$startoftheYear=date('W', strtotime(date('1-1-'.$yearInfuture)))=='01'?01:date('W', strtotime(date('7-1-'.$yearInfuture)));
$daysToGoFWD=2*(($weekInfuture-$startoftheYear)+($enofTheYear-$currentWeek)+2);
}
$currentTime=strtotime("+$daysToGoFWD days", $originalTime);
while (date('w', $currentTime)==0 || date('w', $currentTime)==6){
$currentTime=strtotime("+1 days", $currentTime);
}
return date('Y-m-d',$currentTime);
}
Ok this seem to be a correct solution to the problem.Howver I am still looking optimized simplar solution.Please do post your ideas
Bookmarks