了解しました。クロックイン/クロックアウトが4回発生しています。出勤、昼食のための出勤、昼食からの出勤、そして最後の出勤があります。これは24時間制であり、時間は最後に最も近い.25(15分)に丸める必要があります。
*For reference, a is the first clock in hour, b is the clock out for lunch hour
c is the clock in hour from lunch, and d is the final clock out hour
*e is the first clock in minute, f is the clock out for lunch minute
g is the clock in from lunch minute, and h is the final clock out minute
*So for example, if somebody clocked in at 5:30, a=5 and f=30
a clock out for lunch at 12:00 gives b=12 and g=0, etc.
*The way this code works in a nutshell is to find the total time elapsed and then
subtract the lunch break time from it.
//Find total time
a=d-a;
e=h-e;
//Find lunch break time
y=c-b;
z=g-f;
if(e>=0 && z>=0){
hours=a-y;
minutes=e-z;
if(minutes<0){minutes=minutes*(-1);}
}else if(e<0 && z<0){
e=e*(-1);
z=z*(-1);
hours=a-y;
minutes=e-z;
if(minutes<0){minutes=minutes*(-1);}
}else{
if(e<0){e=e*(-1);}
if(z<0){z=z*(-1);}
if(e<=z){hours=a-y-1;}
else{hours=a-y;}
minutes=e-z;
if(minutes<0){minutes=minutes*(-1);}
}
a=hours;
e=minutes;
//This rounds to the nearest 15 minutes/quarter hour
if(e<15){
if(e>=8){e=15;}
else if(e<8){e=0;}}
if(e<=30 && e>=15){
if(e>=23){e=30;}
else if(e<23){e=15;}}
if(e<=45 && e>30){
if(e>=38){e=45;}
else if(e<38){e=30;}}
if(e<=60 && e>45){
if(e>=53){e=0;}
else if(e<53){e=45;}}
e=e/60;
a=a+e;
}
if(a<0){a=a+24;}
$(totaltime).attr('value',a);
}
コードは動作に非常に近く、動作しない場合がランダムにあり、1時間または0.5時間ほどずれます。また、これは非常に制限されたサーバーでホストされているHTMLページのJavaScriptで記述されているため、新しいライブラリなどを実際に追加することはできません。
より良いアイデアがあれば、間違いなく私のコードをスクラップしてください。これらの3つのif / elseステートメントは説明が少しわかりにくいため、コードが機能しないのはそのためです。私は主に、これにいくらかの努力を払っており、あなたの助けを利用しようとしているだけではないことを示すためにコードを示しました。
私もお詫びしますが、しばらくコンピュータから離れなければならないので、この問題を解決するための提案や方法があれば、それらを投げてください。戻ってきたらそれらを見ていきます。