Java LocalDate Calculate isOverlapping(LocalDate firstStartDate, LocalDate firstEndDate, LocalDate secondStartDate, LocalDate secondEndDate)

Here you can find the source of isOverlapping(LocalDate firstStartDate, LocalDate firstEndDate, LocalDate secondStartDate, LocalDate secondEndDate)

Description

is Overlapping

License

Apache License

Declaration

private static boolean isOverlapping(LocalDate firstStartDate, LocalDate firstEndDate,
            LocalDate secondStartDate, LocalDate secondEndDate) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.time.LocalDate;

public class Main {
    private static boolean isOverlapping(LocalDate firstStartDate, LocalDate firstEndDate,
            LocalDate secondStartDate, LocalDate secondEndDate) {
        boolean isOverlapping = false;

        if ((firstStartDate == null && firstEndDate == null) || (secondStartDate == null && secondEndDate == null)
                || (firstStartDate == null && secondStartDate == null)
                || (firstEndDate == null && secondEndDate == null)) {
            isOverlapping = true;//ww w  . j  a  v  a2  s  . co  m
        }

        if (firstStartDate != null && secondStartDate == null && secondEndDate != null) {
            if (firstStartDate.compareTo(secondEndDate) <= 0) {
                isOverlapping = true;
            }
        }

        if (firstEndDate != null && secondStartDate != null && secondEndDate == null) {
            if (firstEndDate.compareTo(secondStartDate) >= 0) {
                isOverlapping = true;
            }
        }

        if (firstStartDate != null && firstEndDate != null && secondStartDate != null && secondEndDate != null) {
            if (firstStartDate.compareTo(secondStartDate) <= 0 && firstEndDate.compareTo(secondStartDate) >= 0) {
                isOverlapping = true;
            }
        }

        return isOverlapping;
    }
}

Related

  1. isInPeriod(LocalDate subject, LocalDate start, LocalDate end)
  2. isLess(@Nonnull final LocalDate aDate1, @Nonnull final LocalDate aDate2)
  3. isLocalDateAD(LocalDate date)
  4. isLocalDateOrDateTimeType(Class type)
  5. isNotNullAndAfter(LocalDate localDate1, LocalDate localDate2)
  6. isValid(LocalDate ld1, LocalDate ld2, ZoneId zid, Predicate test)
  7. isWeekend(LocalDate date)
  8. isWorkDay(@Nonnull final LocalDate aDate)
  9. lastMonth(LocalDate date)