Reputation: 491
Im making kinda widget showing weather now is working time or not. Pretty easy just match current time with start & end time! But the whole logic fails if Company' working hours from evening to morning:
var atWork = 'false';
var start = 22; //working day starts
var end = 7; //working day ends
var nowt = 1; //
if (start>=end) {//nightshift
end+=12; start -=12;
if (nowt > 0 && nowt <12) nowt += 12; else nowt-=12;
if (start < nowt && nowt< (end-12)){ atWork = 'true'; }
}
else { //normal
if (nowt >= start && nowt <end){atWork = 'true'; }
}
$('#debug').html(atWork+' start: '+start+' end: '+end+' curtime: '+nowt);
thanks to gurvinder372 i've came up to this solution... But still not working properly(
Upvotes: 0
Views: 43
Reputation: 491
if ((start >= end) && (t >= start || t <= end)){
atWork = 'true'; }
Upvotes: 0
Reputation: 723
function check(start, end, current) {
return ((current >= start || current <= end) && end <= start) ||
(current <= end && current >= start);
}
Upvotes: 2
Reputation: 68393
Interesting problem!
This clearly is a scenario of a night shift, you need to bring it to day shift :)
var atWork = false;
var start = 8; //working day starts from 8 o'clock
var end = 19; //working day ends at 19 o'clock
var nowt = servertime(gmt);
/*****this part has been added****/
if (nightShift)
{
end += 12; start -= 12; nowt -= 12;
if (nowt < 0)
{
nowt += 12;
}
}
/*********************************/
if (nowt >= start && nowt <end)
{
atWork = true;
}
Please note that this logic assumes that a shift is for 8-12 hours only.
Upvotes: 1