javascript - How to find if there's a conflict between two sets of ranges of times -
i have database of schedule of classes , user wants add class. purpose of application not handle having classes during same time period. have database full of start , end times of classes in schedule , start , end times of class user wants add. need validate these times not overlap have set loop goes through each class of schedule , uses moment.js's isbetween()
feature, doesn't seem work inputed start time less database start time , has other flaws can't think of @ midnight. have suggestions on how tackle this? here example of code have right now.
$$.each(scheduledb({monday: true}).get(), function(index, value) { if(moment($$('#start_time'), "hh:mm").isbetween(moment(value['start_time'], "hh:mm"),moment(value['end_time'], "hh:mm"))) { $$('#error-block').show(); $$('#error-block-text').text('could not add class because time conflicted ' + value['name'] + '.'); console.log('start time conflict'); } if(moment($$('#end_time'), "hh:mm").isbetween(moment(value['start_time'], "hh:mm"),moment(value['end_time'], "hh:mm"))) { $$('#error-block').show(); $$('#error-block-text').text('could not add class because time conflicted ' + value['name'] + '.'); console.log('end time conflict'); } });
Comments
Post a Comment