A small, focused Java library that provides immutable range types and helpers for:
- Date ranges (weekly, bi‑weekly, semi‑monthly, monthly, quarterly, semi‑annual, annual)
- Time ranges during a day
- DateTime ranges (combining a date and a time range)
The library emphasizes simple, composable value objects with predictable navigation (prior/next), containment, overlap, and iteration helpers.
- Java: 21
- Build: Gradle (Kotlin DSL)
- Tests: JUnit 5 and Spock
- Code coverage: JaCoCo
Group and version are configured as:
- group:
com.stano - version:
1.0.0-SNAPSHOT
You can build and use this project locally via mavenLocal() or consume it directly as a Gradle project dependency.
./gradlew clean buildThis will compile the code, run tests, and generate coverage reports (see build/reports/jacoco/test/html/index.html).
./gradlew publishArtifacts will be written to build/staging-deploy and can be zipped with:
./gradlew zipStagingDeployIf you prefer resolving from mavenLocal(), add it in your consuming project and copy/publish the artifacts to ~/.m2/repository as needed. The coordinates are:
com.stano:date-range:1.0.0-SNAPSHOT
repositories {
mavenLocal()
mavenCentral()
}
dependencies {
implementation("com.stano:date-range:1.0.0-SNAPSHOT")
}- com.stano.daterange
- DateRange: immutable date range with inclusive start and end, iterable over days.
- WeeklyDateRange, BiWeeklyDateRange, SemiMonthlyDateRange, MonthlyDateRange, QuarterlyDateRange, SemiAnnualDateRange, AnnualDateRange: helpers to construct DateRange instances with appropriate navigation.
- DateUtils: month/day helpers.
- com.stano.timerange
- TimeRange: immutable time-of-day range with overlap logic (handles midnight edge cases).
- com.stano.datetimerange
- DateTimeRange: immutable date-time range with containment/overlap and helper factories (e.g., from a TimeRange on a given date, allDay).
import com.stano.daterange.*;
import java.time.*;
DateRange week = WeeklyDateRange.withStartDate(LocalDate.of(2025, 1, 1));
LocalDate first = week.startDate(); // 2025-01-01
LocalDate last = week.endDate(); // 2025-01-07
DateRange nextWeek = week.next(); // shifts by 7 days
boolean overlaps = week.overlaps(nextWeek); // falseimport com.stano.daterange.*;
import java.time.*;
DateRange jan = MonthlyDateRange.withEndDateOnFirst(LocalDate.of(2025, 1, 31));
// jan.startDate() == 2025-01-01, jan.endDate() == 2025-01-31
DateRange feb = jan.next();import com.stano.timerange.*;
import com.stano.datetimerange.*;
import java.time.*;
TimeRange tr = TimeRange.of(LocalTime.of(22, 0), LocalTime.of(1, 0)); // spans midnight
LocalDate date = LocalDate.of(2025, 3, 10);
DateTimeRange dtr = DateTimeRange.fromTimeRangeOnDate(tr, date);
// dtr covers 2025-03-10T22:00 to 2025-03-11T01:00./gradlew test- Spock (Groovy) and JUnit 5 tests are located under src/test/groovy/... and run on the JUnit Platform.
- Coverage reports are produced by JaCoCo.
The build includes a SonarQube plugin. To use it, provide the following properties (for example via gradle.properties or environment variables resolved into com.stano.sonar.host and com.stano.sonar.token):
- sonar.host.url
- sonar.token
Then run:
./gradlew sonarThis project is licensed under the Apache License, Version 2.0. See LICENSE and NOTICE for details.