hi, good day, i'm actually want to compare a date see whether is the date fall into the range between start date and end date , is that any utility class in apache common that can help up this ? or anyone can suggest the idea to compare ? thank you for guidance
so in this case , new start and end date have fall into existing start and end date range, cause it should not interlapse the date range - in short, new start_date and end_date cannot in between of existing start_date and end_date , how i write a algorithm on this ? thank you for guidance
Are you checking two ranges for overlap? See if this makes sense:
What would you think about making a DateRange class with methods like:
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Since your comparison method is mainly for comparing, you shouldn't keep the conversion codes in it.
There're only 4 situations whereby 2 date ranges overlap: 1. Range 1 is larger than Range 2 entirely 2. Range 1 is the same as Range 2 3. Range 1's end date is the same or later than Range 2's start date 4. Range 1's start date is the same or earlier than Range 2's end date
Focus on getting these conditions right first, without bothering about the conversion from String to Date objects. Write a separate method to do the conversion. This way, you would know which is the method that is wrong.
Testing for your conditions #3 && #4 -> true is sufficient. My example was the negative of the same per DeMorgan: !#3 || !#4 -> false.
If I were the mentor or teacher in this situation, I'd love to see:
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi