Calculate working day (Jessie Look)
Last Update:2017-02-28
Source: Internet
Author: User
There's still a problem.
Monday, Tuesday can not do holidays
There may be problems on the algorithm, waiting for your update ...
/**
* Sports98
* Flyruns@hotmail.com (Welcome to Exchange)
*/
================
<title> working days (within one year of calculation) </title>
<style type= "Text/css" >
BODY,TD {font-size:12px}
</style>
<body>
<form action= "<?=$_SERVER[PHP_SELF]?>" method= "Post" Name= "Form1" >
<table cellpadding=0 cellspacing=0 border=0>
<TR><TD colspan=2 height=30 align=center> working day calculator (calculated within one year)
<tr><td> Start Date: <td><input type= "text" name= "StartTime" value= "<?=date (" Y ")? >-01-01" >
<tr><td> End Date: <td><input type= "text" name= "Endtime" value= "<?=date (" y-m-d ")?>" >
<tr><td> Week rest: <td><input type= "text" size=1 name= "Rest" value= "2" > Day of Holiday:
<select name= "Restday" >
<option value= "1" > Monday </option>
<option value= "2" > Tuesday </option>
<option value= "3" > Wednesday </option>
<option value= "4" > Thursday </option>
<option value= "5" > Friday </option>
<option value= "6" selected> Saturday </option>
<option value= "7" > Week VII </option>
</select>
<TR><TD valign=top> Legal Holidays:<td>
<textarea name= "Ordainrest" rows=7>05-01&5
10-01&5</textarea> (& Separate)
<tr><td> absence days: <td><input type= "text" size=1 name= "Absent" value= "0" > Days (Leave no Work day)
<tr><td> overtime days: <td><input type= "text" size=1 name= "overtime" value= "0" > Days
<tr><td> holiday days: <td><input type= "text" size=1 name= "supplytime" value= "0" > Days
<input type= "submit" value= "Calculated data" >
</table>
</form>
<?php
if (Is_array ($_post)) {//have POST data
$starttime =date ("Z", Mktime (0,0,0,substr ($_post[starttime],5,2), substr ($_post[starttime],8,2), substr ($_post[ starttime],0,4)));
$endtime =date ("Z", Mktime (0,0,0,substr ($_post[endtime],5,2), substr ($_post[endtime],8,2), substr ($_post[endtime), 0,4)));
$alltime = $endtime-$starttime +1;
echo "From start date to end date, total:". $alltime. " Days ";
echo "<br> absence days:. $_post[absent]." Days ";
echo "<br> Overtime Date:". $_post[overtime]. " Days ";
echo "<br> holiday period:". $_post[supplytime]. " Days ";
echo "<br> statutory holiday:<br>";
$tmpa =explode ("\ n", $_post[ordainrest]);
for ($TMPB =0; $TMPB <count ($tmpa); $TMPB + +) {
$TMPC =explode ("&", $tmpa [$TMPB]);
echo "". $TMPC [0]. "Rest". $TMPC [1]. "Day <br>";
$tmpsize =date ("Z", Mktime (0,0,0,substr ($TMPC [0],0,2), substr ($TMPC [0],3,2), Date ("Y"))]/date data for the holiday
if ($tmpsize >= $starttime && $tmpsize <= $endtime) {
$alltime = $alltime-$TMPC [1];//Remove legal date from total work day
}
}
Debugging points
echo "
$alltime-=$_post[absent];//excluding days of absence
$alltime +=$_post[overtime];//Plus Overtime date
$alltime-=$_post[supplytime];//to remove the supplemental holiday
Calculate Week rest Day
$fweek =date ("W", Mktime (0,0,0,substr ($_post[starttime],5,2), substr ($_post[starttime],8,2), substr ($_post[ starttime],0,4));//number of weeks to get start date
$eweek =date ("W", Mktime (0,0,0,substr ($_post[endtime],5,2), substr ($_post[endtime],8,2), substr ($_post[endtime), 0,4));//End of week
Here's how to judge the start of Sunday (the number of dates required for the first week)
if ($fweek <$_post[restday]) {//Is not a rest day (designated work day of rest), at designated rest days
$ctmp =abs ($_post[restday]-$fweek);
$runday =date ("D", Mktime (0,0,0,substr ($_post[starttime],5,2), $ctmp +substr ($_post[starttime],8,2), substr ($_post[ starttime],0,4)));
Get the first week's date
}else{//to designate rest days (e.g. $FWWK =6 $_post[restday]=2)
$ctmp =abs ($fweek-$_post[restday]);
$runday =date ("D", Mktime (0,0,0,substr ($_post[starttime],5,2), $ctmp +substr ($_post[starttime],8,2), substr ($_post[ starttime],0,4)));
}
Debugging points
echo "for ($ttmpa = 0;;; $ttmpa + +) {
Push the current holidays backwards 7th, to determine the final $ttmpa for the number of holidays
$cday =date ("Z", Mktime (0,0,0,substr ($_post[starttime],5,2), $runday +7* $ttmpa, substr ($_post[starttime],0,4)));
if ($cday > $endtime) {
Break
}
}
echo "<br> start Date:". Date ("Y-m-d w", Mktime (0,0,0,substr ($_post[starttime],5,2), substr ($_post[starttime],8,2) , substr ($_post[starttime],0,4)));
echo "<br> End Date:". Date ("Y-m-d Week W", Mktime (0,0,0,substr ($_post[endtime],5,2), substr ($_post[endtime],8,2), SUBSTR ($_post[endtime],0,4)));
echo "<br> Total weekend break:". $ttmpa. " X ". $_post[rest]." = ". $ttmpa *$_post[rest]." Day <span onclick=\ "if" (document.all[' Allweek '].style.display== ') {this.innerhtml= ' (+) ';d ocument.all[' Allweek ']. Style.display= ' None ';} Else{this.innerhtml= ' (-) ';d ocument.all[' allweek '].style.display= ';} \ "style=\" cursor:hand\ "> (+) </span>";
echo "<div id=\" allweek\ "style=\" display: ' None ' > ';
for ($TTmpa =0; $TTmpa < $ttmpa; $TTmpa + +) {
$dday =date ("Y-m-d Week W", Mktime (0,0,0,substr ($_post[starttime],5,2), $runday +7* $TTmpa, substr ($_post[starttime],0,4 )));
echo "$dday <br>";
}
echo "</div>";
if ($fweek ==6) {//Saturday
}else if ($fweek ==0) {//Sunday, the total rest day is only one day rest day
Add a day to $alltime +=1;//
}
$allcday = $ttmpa *$_post[rest];//Total work day off
$alltime-= $allcday;
echo "<HR size=1> effective working day: <font color=red> $alltime </font>";
}
?>
</body>