I have an object Date with 2 date fields Field1 and Field2. Now, I have a resource and when I am allocating that resource for a period of time, a record is created in the Date object and the start and end dates of the resource will be the values of Field1 and Field2 respectively.

Now my requirement is when I add the same resource for dates that are conflicting with the existing date, I need to throw an error.

My question is how do I take the values of the dates between when the difference between Field1 and Field2 are not constant?

Ex: The first time I book a resource, I book it from Jan '17 to June '17. Now, when I try to book the same resource between April '17 to May '17, I need to get an error. Notice that the 2 date fields don't have a constant period.

Also, I didn't use the standard Public Calendar and Resources as an event can last for only 14 days and my requirement needs me to create events longer than that which is not possible


1 Answer 1


This is the basic logic for checking if two date ranges overlap:

public class DateRange {
    public Date start;
    public Date through;
    public Boolean intersects(DateRange that) {
        if (that.through < this.start) return false;
        else if (that.start > this.through) return false;
        else return true;

so add this sort of logic to your code.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .