Step 1. Add the JitPack repository to your build file
Add it in your root settings.gradle at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url 'https://jitpack.io' }
}
}
Add it in your settings.gradle.kts at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url = uri("https://jitpack.io") }
}
}
Add to pom.xml
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
Add it in your build.sbt at the end of resolvers:
resolvers += "jitpack" at "https://jitpack.io"
Add it in your project.clj at the end of repositories:
:repositories [["jitpack" "https://jitpack.io"]]
Step 2. Add the dependency
dependencies {
implementation 'com.github.mbi88:date-handler:1.0.4'
}
dependencies {
implementation("com.github.mbi88:date-handler:1.0.4")
}
<dependency>
<groupId>com.github.mbi88</groupId>
<artifactId>date-handler</artifactId>
<version>1.0.4</version>
</dependency>
libraryDependencies += "com.github.mbi88" % "date-handler" % "1.0.4"
:dependencies [[com.github.mbi88/date-handler "1.0.4"]]
Lightweight and test-friendly Java library for date/time manipulation and parsing using intuitive formula syntax.
Built on top of Joda-Time.
1y2M3d4h5m6s)yyyy-MM-dd and yyyy-MM-dd'T'HH:mm:ssDateTimeZoneimplementation("com.mbi:date-handler:1.0")
implementation 'com.mbi:date-handler:1.0'
Formula is a string composed of pairs: number + unit. Example:
1y – one year2M – two months3d – three days4h – four hours5m – five minutes6s – six secondsYou can combine them like this:
1y2M3d4h5m6s → adds full period to date
import com.mbi.DateHandler;
import org.joda.time.DateTimeZone;
import org.testng.annotations.Test;
import java.util.TimeZone;
public class DateHandlerTest {
@Test
public void testName() {
DateHandler dateHandler = new DateHandler(DateTimeZone.forTimeZone(TimeZone.getTimeZone("Europe/Kiev")));
// Current time is 2018-03-20T11:34:18. Method will return: 2022-05-20T13:34:18
System.out.println(dateHandler.plus("4y2M2h"));
// Returns 365
System.out.println(dateHandler.daysBetweenDates("2017-01-01", "2018-01-01"));
// Returns Tuesday
System.out.println(dateHandler.getDayOfWeek("2019-01-01"));
}
}
Add to now:
date.plus("3d5h") → adds 3 days and 5 hours to current datetime
Subtract from now:
date.minus("1M") → subtracts 1 month
Add to specific date:
date.plus("2024-01-01", "2d") → "2024-01-03"
Subtract from datetime:
date.minus("2024-01-04T01:00:00", "1d2h") → "2024-01-02T23:00:00"
Get parts of date:
date.getYear("2023-05-01T13:15:30") → 2023
date.getMonth() → current month
Get weekday:
date.getDayOfWeek("2024-03-25") → "Monday"
Days between dates:
date.daysBetweenDates("2023-01-01", "2023-01-10") → 9
date.plus("abc"); // Invalid format: must start with digit and end with letter
date.plus("1y2M3"); // Invalid format
date.plus("2d5mx"); // Unrecognized field: d5mx
This library is built for automation use:
DateHandler supports any DateTimeZone. Default is UTC. Example:
DateHandler handler = new DateHandler(DateTimeZone.forTimeZone(TimeZone.getTimeZone("Europe/Kiev")));
This project is licensed under the MIT License — see the LICENSE file for details.
🕒 Built on Joda-Time · 💡 Formula-based manipulation · ✅ Ready for testing