jeudi 24 mai 2018

How to alert the user if there is already schedule is set of the day?

Here I'm using jQuery to alert a user if he/she want to add a schedule on a particular time but that time is already exists in the db. Suppose let us take an example of this there is a User having a schedule on Monday is 8:00AM to 10:00AM and there is another schedule of same user is 1:00PM to 3:00PM but if the user want to add another time of PM like 1:00PM to 4:00PM or 1:30PM to 4:00PM then the system first check that there is time exists between them then it will alert. This all is done in golang api then there is a little problem in Jquery like I retrieved all data from my api but while arranging them like I told above that 1:00PM to 3:00PM if user want to add the other schedule like 1:30PM to 4:00PM then it will show the other times too like 8:00AM to 10:00AM too why it is showing like that below code I'm using:-

for(var m = 0; m< timearray.length; m++){
        for (var l = 0; l < array_time.length; l++) {
           if (array_time[l].start_time == timearray[m].start_time && array_time[l].end_time == timearray[m].end_time) {
                console.log("hello 1")
                result_dates.push(convertTime24to12(secondsTimeSpanToHMS(timearray[m].start_time))+" "+convertTime24to12(secondsTimeSpanToHMS(timearray[m].end_time)));
                                    }
                if (array_time[l].start_time < timearray[m].start_time && array_time[l].end_time == timearray[m].end_time) {
                    console.log("hello 2")
                    result_dates.push(convertTime24to12(secondsTimeSpanToHMS(timearray[m].start_time))+" "+convertTime24to12(secondsTimeSpanToHMS(timearray[m].end_time)));
                                    }
                if (array_time[l].start_time == timearray[m].start_time && array_time[l].end_time > timearray[m].end_time) {
                    console.log("hello 3")
                    result_dates.push(convertTime24to12(secondsTimeSpanToHMS(timearray[m].start_time))+" "+convertTime24to12(secondsTimeSpanToHMS(timearray[m].end_time)));
                                    }
                if (array_time[l].start_time < timearray[m].start_time && array_time[l].end_time > timearray[m].end_time) {
                    console.log("hello 4")
                    result_dates.push(convertTime24to12(secondsTimeSpanToHMS(timearray[m].start_time))+" "+convertTime24to12(secondsTimeSpanToHMS(timearray[m].end_time)));
                                    }
                if (array_time[l].start_time > timearray[m].start_time && array_time[l].end_time == timearray[m].end_time){ 
                    console.log("hello 5")
                    result_dates.push(convertTime24to12(secondsTimeSpanToHMS(timearray[m].start_time))+" "+convertTime24to12(secondsTimeSpanToHMS(timearray[m].end_time)));
                                    }
                if (array_time[l].start_time > timearray[m].start_time || array_time[l].end_time > timearray[m].end_time){ 
                    for (var n = timearray[m].start_time; n < timearray[m].end_time; n++) {
                        if (timearray[m].start_time == array_time[l].start_time) {
                            console.log("hello 6")
                            result_dates.push(convertTime24to12(secondsTimeSpanToHMS(timearray[m].start_time))+" "+convertTime24to12(secondsTimeSpanToHMS(timearray[m].end_time)));
                }
            }
        }
    }
}

Here timearray is a array in which there is scheduled time is set and in the array_time the time user want to save in the data base.

  • In first condition it check if start time and end time are same them this will execute.

  • In second condition if the start time is less then the existing time and end time is equal to the existing end time then this will execute.

  • In third condition if the end time is more then the existing end time and the start time is same then this will execute.

  • In forth condition if start time is less the the existing start time and end time is more then the existing end time then this will execute.

  • in fifth condition it will check that if start time is less then the existing start time and end time remain same then this will executed.

  • Not Working properly:- In this condition if the user add start time like "1:30PM to 4:00PM" then it will not working properly it will also push the data of the timing "8:00AM to 10:00AM". What should i have to apply on it that it will show only the time between the "1:00PM to 3:00PM".

Can anybody please help me to solving this problem. Thank you. Hope you will understand what I want to say.

Aucun commentaire:

Enregistrer un commentaire