TemporalPeriods4j
is a library providing temporal periods to extend java.time
API .
TemporalPeriods4j
provides three temporal periods: DatePeriod
, DateTimePeriod
and YearMonthPeriod
.
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
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
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)
.
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);
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);
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));
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'
}
You can build application using following command:
./gradlew clean build -x signArchives
JDK >= 1.8
You can run unit tests using following command:
./gradlew test -x signArchives
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.
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