开发者

How to deal with Time Conflicts?

I am facing a problem to deal with time conflicts. I am creating a system where users will have to insert start time and end time for two different events. like-

  Event-1 Day  StartTime-1 EndTime1

  Event-2 Day  StartTime-2 EndTime2

I have text boxes to input time. Now how to deal with this matter when any user inputs start and end time for an event that conflicts 开发者_Go百科with the time of other the event? For example:

 Event-1  Sunday  2:30 PM 4:30 PM

 Event-2  Sunday  3:00 PM 4:00 PM   

Would you please kindly help me, how to solve this problem? Thanks in Advance


Check whether they are overlapping. Using Date.parse() and just comparing numbers: http://jsfiddle.net/VGyRW/1/.

var i1 = Date.parse($('#i1').val()); // this is jQuery but comes down to the value of first select
var i2 = Date.parse($('#i2').val());
var i3 = Date.parse($('#i3').val());
var i4 = Date.parse($('#i4').val());

if(i1 > i4 && i2 > i4 || i1 < i3 && i2 < i3) {
    // begin and end of first must be both larger than end of second,
    // or both smaller than begin of second
    alert('ok');
} else { 
    alert('not ok');
}


I see no problem with that. Can't you imagine user have party from 1:00 AM to 8:00 AM and another event sleeping from 6:00AM to 11:00 AM?

So answer: Do not solve it. It isn't a problem


Simply change the time from HH:MM format to HH:MM:SS. In other words, add the seconds to it too.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜