Timestone is a Java library for abstracting time sources, enabling deterministic and testable time-dependent logic.
It provides interfaces and implementations for system time and mutable time, compatible with Java's Clock.
Timeinterface for accessing current time and sleeping.SystemTimefor real system clock.MutableTimefor controllable time in tests.- Seamless integration with Java's
Clock.
Import the Timestone API in your project.
If you're using Maven, add the following dependency to your pom.xml:
<dependencies>
<dependency>
<groupId>io.github.predatorray</groupId>
<artifactId>timestone-api</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>io.github.predatorray</groupId>
<artifactId>timestone-test</artifactId>
<version>1.0.0</version>
<scope>test</scope>
</dependency>
</dependencies>If you're using Gradle, add the following to your build.gradle:
dependencies {
implementation 'io.github.predatorray:timestone-api:1.0.0'
testImplementation 'io.github.predatorray:timestone-test:1.0.0'
}// Use system time
import io.github.predatorray.timestone.Time;
import io.github.predatorray.timestone.SystemTime;
Time time = Time.SYSTEM;
long nowMillis = time.millis();
time.sleep(1000);// Use mutable time in tests
import io.github.predatorray.timestone.test.MutableTime;
MutableTime testTime = new MutableTime();
testTime.advance(Duration.ofSeconds(5));For more detailed usage examples, check out the Timestone Examples repository.
This project is licensed under the MIT License.