overlapping-date-ranges is a library to centralize and help people dealing with overlapping date ranges verifications!
- Requires JDK 1.8 or higher;
To add a dependency on overlapping-date-ranges using Maven, use the following:
<dependency>
<groupId>com.github.mawippel</groupId>
<artifactId>overlapping-date-ranges</artifactId>
<version>1.0.5</version>
</dependency>
To add a dependency using Gradle:
dependencies {
implementation 'com.github.mawippel:overlapping-date-ranges:1.0.5'
}
In this case, the toCompare
period overlaps the comparable
one, so, it returns true
as it's overlapping.
LocalDate comparableInit = LocalDate.of(2019, 05, 01);
LocalDate comparableEnd = LocalDate.of(2019, 05, 05);
LocalDate toCompareInit = LocalDate.of(2019, 05, 03);
LocalDate toCompareEnd = LocalDate.of(2019, 05, 10);
boolean isOverlap = OverlappingVerificator.isOverlap(comparableInit, comparableEnd, toCompareInit, toCompareEnd);
In this case, the toCompare
time period overlaps the comparable
one, so, it returns true
as it's overlapping.
LocalDateTime comparableInit = LocalDateTime.of(2019, 05, 05, 9, 10);
LocalDateTime comparableEnd = LocalDateTime.of(2019, 05, 05, 10, 15);
LocalDateTime toCompareInit = LocalDateTime.of(2019, 05, 05, 10, 00);
LocalDateTime toCompareEnd = LocalDateTime.of(2019, 05, 05, 11, 00);
boolean isOverlap = OverlappingVerificator.isOverlap(comparableInit, comparableEnd, toCompareInit, toCompareEnd);
If some of the end dates is before of the initial dates, a DateTimeException
will be thrown, as shown bellow
LocalDate comparableInit = LocalDate.of(2019, 05, 02);
LocalDate comparableEnd = LocalDate.of(2019, 05, 03);
LocalDate toCompareInit = LocalDate.of(2019, 05, 05);
LocalDate toCompareEnd = LocalDate.of(2019, 05, 04);
OverlappingVerificator.isOverlap(comparableInit, comparableEnd, toCompareInit, toCompareEnd);
The behavior for the LocalDateTime
's method is the same.