計(jì)算工作日(jessie看)
發(fā)表時(shí)間:2023-04-07 來源:明輝站整理相關(guān)軟件相關(guān)文章人氣:
[摘要]現(xiàn)在還有問題周一,周二不能做節(jié)假日可能算法上還有問題,等待你的更新.../*** sports98* flyruns@hotmail.com (歡迎交流)*/================<...
現(xiàn)在還有問題
周一,周二不能做節(jié)假日
可能算法上還有問題,等待你的更新...
/**
* sports98
* flyruns@hotmail.com (歡迎交流)
*/
================
<html>
<head>
<title>計(jì)算工作日(計(jì)算一年內(nèi))</title>
</head>
<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>工作日計(jì)算器(計(jì)算一年內(nèi))
<tr><td>開始日期:<td><input type="text" name="starttime" value="<?=date("Y")?>-01-01">
<tr><td>結(jié)束日期:<td><input type="text" name="endtime" value="<?=date("Y-m-d")?>">
<tr><td>周休息數(shù):<td><input type="text" size=1 name="rest" value="2">天 始休日:
<select name="restday">
<option value="1">星期一</option>
<option value="2">星期二</option>
<option value="3">星期三</option>
<option value="4">星期四</option>
<option value="5">星期五</option>
<option value="6" selected>星期六</option>
<option value="7">星期七</option>
</select>
<tr><td valign=top>法定假期:<td>
<textarea name="ordainrest" rows=7>05-01&5
10-01&5</textarea>(&進(jìn)行分隔)
<tr><td>缺席天數(shù):<td><input type="text" size=1 name="absent" value="0">天(請(qǐng)假等未工作日)
<tr><td>加班天數(shù):<td><input type="text" size=1 name="overtime" value="0">天
<tr><td>補(bǔ)假天數(shù):<td><input type="text" size=1 name="supplytime" value="0">天
<input type="submit" value="計(jì)算數(shù)據(jù)">
</form>
<?php
if(is_array($_POST)){//有POST數(shù)據(jù)
$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 "自開始日期到結(jié)束日期,共:".$alltime."天";
echo "<br>缺席天數(shù):".$_POST[absent]."天";
echo "<br>加班日期:".$_POST[overtime]."天";
echo "<br>補(bǔ)假日期:".$_POST[supplytime]."天";
echo "<br>法定假期:<br>";
$tmpa=explode("\n",$_POST[ordainrest]);
for($Tmpb=0;$Tmpb<count($tmpa);$Tmpb++){
$tmpc=explode("&",$tmpa[$Tmpb]);
echo "".$tmpc[0]." 休息 ".$tmpc[1]." 天<br>";
$tmpsize=date("z",mktime(0,0,0,substr($tmpc[0],0,2),substr($tmpc[0],3,2),date("Y")));//節(jié)假日的日期數(shù)據(jù)
if($tmpsize>=$starttime && $tmpsize<=$endtime){
$alltime=$alltime-$tmpc[1];//從總的工作日中去掉法定日期
}
}
//調(diào)試點(diǎn)
//echo "<h3>$starttime $endtime</h3>";
$alltime-=$_POST[absent];//扣除缺席天數(shù)
$alltime+=$_POST[overtime];//加上加班日期
$alltime-=$_POST[supplytime];//去掉補(bǔ)充的假期
//計(jì)算周休息日
$fweek=date("w",mktime(0,0,0,substr($_POST[starttime],5,2),substr($_POST[starttime],8,2),substr($_POST[starttime],0,4)));//獲得開始日期的周數(shù)
$eweek=date("w",mktime(0,0,0,substr($_POST[endtime],5,2),substr($_POST[endtime],8,2),substr($_POST[endtime],0,4)));//結(jié)束周數(shù)
//這里要判斷一下開始的星期天數(shù)(要求獲得第一周的日期數(shù))
if($fweek<$_POST[restday]){//不是休息日(指定的工作休息日),在指定休息日前
$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)));
//獲得第一周的日期
}else{//再指定休息日后(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)));
}
//調(diào)試點(diǎn)
//echo "<h3>$runday $ctmp $_POST[restday] $fweek</h3>";
for($ttmpa=0;;$ttmpa++){
//將當(dāng)前的節(jié)假日向后推7日,進(jìn)行判斷最終$ttmpa為節(jié)假日數(shù)
$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>開始日期:".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>結(jié)束日期:".date("Y-m-d 星期w",mktime(0,0,0,substr($_POST[endtime],5,2),substr($_POST[endtime],8,2),substr($_POST[endtime],0,4)));;
echo "<br>共計(jì)周末休息:".$ttmpa."×".$_POST[rest]."=".$ttmpa*$_POST[rest]."天<span onclick=\"if(document.all['allweek'].style.display==''){this.innerHTML='(+)';document.all['allweek'].style.display='none';}else{this.innerHTML='(-)';document.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 星期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){//周六
}else if($fweek==0){//周日,則總休息日僅僅去一天休息日
$alltime+=1;//增加一天
}
$allcday=$ttmpa*$_POST[rest];//總的工作休息日
$alltime-=$allcday;
echo "<hr size=1>有效的工作日:<font color=red>$alltime</font>";
}
?>
</body>
</html>