I'm making a program to hold a diary for an HCI assignment and I'm having issues for checking when two appointments might have a collision.
The class holds appointments as two (Java) Calendars that hold when the appointment starts and finishes.
I have a method to see if a appointment might have a time collision with another appointment. But I'm having an issue where say, I have an appointment from 1-2pm, and another from 2pm-2:30, the method returns saying there is a collision.
This is my current code:
The class holds appointments as two (Java) Calendars that hold when the appointment starts and finishes.
I have a method to see if a appointment might have a time collision with another appointment. But I'm having an issue where say, I have an appointment from 1-2pm, and another from 2pm-2:30, the method returns saying there is a collision.
This is my current code:
Code:
/**
* This method checks to see if the appointment collides with the
* given appointment.
*/
public boolean checkCollision(Appointment o) {
// Get UNIX time
long start1 = start_.getTimeInMillis();
long start2 = o.start_.getTimeInMillis();
long end1 = finish_.getTimeInMillis();
long end2 = o.finish_.getTimeInMillis();
// Return result
return ((start1 >= start2 && start1 <= end2)
|| (end1 >= start2 && end1 <= end2) || (start1 <= start2 && end1 >= end2));
}