Git Product home page Git Product logo

overlapping-date-ranges's Introduction

overlapping-date-ranges - A Java Overlapping Verificator

Total alerts Language grade: Java

overlapping-date-ranges is a library to centralize and help people dealing with overlapping date ranges verifications!

Compatibility

  • Requires JDK 1.8 or higher;

Adding overlapping-date-ranges to your build

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'
}

Examples

Using LocalDate

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);

Using LocalDateTime

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);

Exceptions

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.

overlapping-date-ranges's People

Contributors

mawippel avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.