Problem: I have a list containg hours, for example:
08:15:00
08:45:00
09:00:00
12:00:00
…
application is allowing user to make an appointment for a specific hour let’say: 8:15:00, each meeting takes half an hour.
Question: How to determine if there is a slot needed for appointment like this? I know that Calendar class have methods before() nad after(), but it doesn’solve my problem. I mean if there is appointment at 12:00 and another one at 12:00, how to prevent before making another one at 12:15?
edit:
I’ve tried using methods I mentioned before, like:
Calendar cal1 = Calendar.getInstance(); // for example 12:00:00
Calendar cal2 = Calendar.getInstance(); // for exmaple 12:30:00
Calendar userTime = Calendar.getInstance(); // time to test: 12:15:00
if(user.after(cal1)&& user.before(cal2)){
... // do sth
}
Check if the date to check is between the two provided:
To book for a determinate hour, I would do a class with two dates and a method to check this:
Then you can simply do an
Scheduleclass extendingArrayList, adding a methodisDateAvailable(Date toCheck), iterating the list of Appointments and checking that there is no one conflicting.