好的,有4個時鐘輸入/輸出實例。有一個時鐘,午餐時鐘,午餐時鐘,最後一個鐘錶。這是一個24小時制,時間需要四捨五入到最接近的0.25。(15分鐘)。需要幫助計算24小時內的4個實例時鐘之間的時間差
*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);
}
的代碼是非常接近的工作,也有隻是隨機的情況下將無法正常工作,它會通過一個小時或一個小時左右.5關閉。另外,這是用javascript寫在託管於高度受限服務器上的HTML頁面上的,所以我無法真正添加任何新庫或任何東西。
如果你有更好的主意,肯定可以放棄我的代碼,這三個if/else語句有點混淆不清,這就是代碼無法正常工作的原因。我主要展示了代碼,以表明我一直在爲此付出一些努力,而不僅僅是試圖利用你的幫助哈哈。
我也很抱歉,但我不得不離開電腦一段時間,所以如果你有一些建議或方法來解決這個問題,請把它們扔出去,當我回來時我會看看它們。
爲什麼要分別存儲分鐘和小時? – Blender
這就是他們如何通過網站獲得輸入。一個領域的時間,另一個領域的分鐘。 – Hoser