https://github.com/predatorray/timestone
a Java library for abstracting time sources, enabling deterministic and testable time-dependent logic
https://github.com/predatorray/timestone
java multithreading testing time
Last synced: 4 months ago
JSON representation
a Java library for abstracting time sources, enabling deterministic and testable time-dependent logic
- Host: GitHub
- URL: https://github.com/predatorray/timestone
- Owner: predatorray
- License: mit
- Created: 2025-07-12T21:47:13.000Z (12 months ago)
- Default Branch: main
- Last Pushed: 2025-07-23T04:43:37.000Z (12 months ago)
- Last Synced: 2025-07-23T06:18:46.684Z (12 months ago)
- Topics: java, multithreading, testing, time
- Language: Java
- Homepage:
- Size: 37.1 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Timestone
[][1]



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`.
## Features
- `Time` interface for accessing current time and sleeping.
- `SystemTime` for real system clock.
- `MutableTime` for controllable time in tests.
- Seamless integration with Java's `Clock`.
## Usage
Import the Timestone API in your project.
If you're using Maven, add the following dependency to your `pom.xml`:
```xml
io.github.predatorray
timestone-api
1.0.0
io.github.predatorray
timestone-test
1.0.0
test
```
If you're using Gradle, add the following to your `build.gradle`:
```groovy
dependencies {
implementation 'io.github.predatorray:timestone-api:1.0.0'
testImplementation 'io.github.predatorray:timestone-test:1.0.0'
}
```
### For Production Code
```java
// 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);
```
### For Unit Tests
```java
// Use mutable time in tests
import io.github.predatorray.timestone.test.MutableTime;
MutableTime testTime = new MutableTime();
testTime.advance(Duration.ofSeconds(5));
```
### More Examples
For more detailed usage examples, check out the [Timestone Examples][2] repository.
## License
This project is licensed under the [MIT License][1].
[1]: ./LICENSE
[2]: ./timestone-examples