Skip to content

MikeSafonov/TemporalPeriods4J

Repository files navigation

TemporalPeriods4j

Java CI with Gradle Conventional Commits Quality Gate Status Reliability Rating Maintainability Rating Security Rating

Bugs Code Smells Vulnerabilities

Duplicated Lines (%) Lines of Code Technical Debt

TemporalPeriods4j is a library providing temporal periods to extend java.time API .

Features

Date, DateTime and YearMonth temporal periods

TemporalPeriods4j provides three temporal periods: DatePeriod, DateTimePeriod and YearMonthPeriod.

class diagram

DatePeriod

DatePeriod is a temporal period between two java.time.LocalDate.

You may use one of the following to create DatePeriod:

  • constructor new DatePeriod(LocalDate from, LocalDate to);
  • static constructors of :
    • DatePeriod.of(LocalDate from, LocalDate to);
    • DatePeriod.of(int yearFrom, int monthFrom, int dayFrom, int yearTo, int monthTo, int dayTo).
  • static constructors from:
    • DatePeriod.from(LocalDateTime from, LocalDateTime to);
    • DatePeriod.from(DateTimePeriod dateTimePeriod).

DateTimePeriod

DateTimePeriod is a temporal period between two java.time.LocalDateTime.

You may use one of the following to create DateTimePeriod:

  • constructor new DateTimePeriod(LocalDateTime from, LocalDateTime to);
  • static constructor of DateTimePeriod.of(LocalDateTime from, LocalDateTime to)
  • static constructors from:
    • DateTimePeriod.from(DatePeriod period, LocalTime time);
    • DateTimePeriod.from(DatePeriod period).

YearMonthPeriod

YearMonthPeriod is a temporal period between two java.time.YearMonth.

You may use one of the following to create YearMonthPeriod:

  • constructor new YearMonthPeriod(YearMonth from, YearMonth to);
  • static constructors of :
    • YearMonthPeriod.of(YearMonth from, YearMonth to);
    • YearMonthPeriod.of(int yearFrom, int monthFrom, int yearTo, int monthTo).
  • static constructors from:
    • YearMonthPeriod.from(LocalDate from, LocalDate to);
    • YearMonthPeriod.from(LocalDateTime from, LocalDateTime to);
    • YearMonthPeriod.from(DatePeriod period);
    • YearMonthPeriod.from(DateTimePeriod period).

Combining two temporal periods

combineWith method creates new period by combining current and specified periods.

Example:

DatePeriod one = DatePeriod.of(2020, 1, 1, 2020, 1, 20);
DatePeriod two = DatePeriod.of(2020, 1, 10, 2020, 1, 25);
DatePeriod combined = one.combineWith(two);

combineWith

Intersection between two temporal periods

intersectionWith method creates new period by finding intersection between current and specified periods.

Example:

DatePeriod one = DatePeriod.of(2020, 1, 1, 2020, 1, 20);
DatePeriod two = DatePeriod.of(2020, 1, 10, 2020, 1, 25);
Optional<DatePeriod> intersection = one.intersectionWith(two);

intersection

Splitting period by temporal point

split method creates array of periods by splitting current period by specified temporal point.

Example:

DatePeriod period = DatePeriod.of(2020, 1, 1, 2020, 1, 31);
DatePeriod[] spl = period.split(LocalDate.from(2020, 1, 10));

split

Usage

Maven:

<dependency>
  <groupId>com.github.mikesafonov</groupId>
  <artifactId>TemporalPeriods4j</artifactId>
  <version>0.0.1</version>
</dependency>

Gradle:

dependencies {
    implementation 'com.github.mikesafonov:TemporalPeriods4j:0.0.1'
}

Build

Build from source

You can build application using following command:

./gradlew clean build -x signArchives

Requirements:

JDK >= 1.8

Unit tests

You can run unit tests using following command:

./gradlew test -x signArchives

Mutation tests

You can run mutation tests using following command:

./grdlew pitest -x signArchives

You will be able to find pitest report in build/reports/pitest/ folder.

Contributing

Feel free to contribute. New feature proposals and bug fixes should be submitted as GitHub pull requests. Fork the repository on GitHub, prepare your change on your forked copy, and submit a pull request.

IMPORTANT!

Before contributing please read about Conventional Commits / Conventional Commits RU

About

No description or website provided.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages