Have a pretty simple question here, but would need some logical expertise to solve this. So, I have an API that returns start and end time, for a given time slot in a 24 hour int format such that : start hour would be 4 and start minute would be 30 and end hour would be 5 and end minute would be 30. Please note that the slots returned are in 30 minute increments, such that a given hour would be from 1 to 24, and given minute would be either 30 or 0.
So now I have a set of ranges, such that each range represents a slot that's been taken and I need to identify whether any given time from the API overlaps or falls within one of these slots. (these slots would have hours from 1 to 24 but minutes could differ, could be anything from 0 to 59).
For this my logic so far is:
for (int i = 0; i < ranges.size(); i++) {
int rangeStartHour = ranges.get(i).getStartTime().getHour();
int rangeEndHour = ranges.get(i).getEndTime().getHour();
int rangeStartMinute = ranges.get(i).getStartTime().getMinute();
int rangeEndMinute = ranges.get(i).getStartTime().getMinute();
if ((rangeStartHour == 0 && rangeEndHour == 24
&& rangeStartMinute == 0 && rangeEndMinute == 0)) {
isAvailable = false;
} else {
isAvailable = true;
}
}
I am missing an if in between where I need to identify whether the given time range falls in between or is equal to any of the taken slots to avoid overlap. Any ideas what would be the best way to go about this? I would love to have a very simple and compact solution that always works for this scenario. Open to all suggestions, worth a try! Happy to share more details if need be to clarify this further Thanks in advance!