https://github.com/plannigan/timeslip
Time manipulation for JVM test cases
https://github.com/plannigan/timeslip
java kotlin testing
Last synced: 3 months ago
JSON representation
Time manipulation for JVM test cases
- Host: GitHub
- URL: https://github.com/plannigan/timeslip
- Owner: plannigan
- License: mit
- Created: 2019-06-16T16:05:23.000Z (about 7 years ago)
- Default Branch: main
- Last Pushed: 2025-07-16T04:25:26.000Z (12 months ago)
- Last Synced: 2025-07-17T07:25:44.463Z (12 months ago)
- Topics: java, kotlin, testing
- Language: Kotlin
- Homepage: https://timeslip.hypercubetools.com/
- Size: 1.11 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 12
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# TimeSlip: Time manipulation for JVM test cases
TimeSlip allows test cases to manipulate time by providing a concrete `java.time.Clock` implementation that will operate
in a deterministic way, independent of the actual passage of time.
The TimeSlip API is specifically designed to be easy to use from Kotlin and Java code.
[][ci]
[](http://kotlinlang.org)
[](https://mvnrepository.com/artifact/com.hypercubetools/timeslip)
[](https://codecov.io/gh/plannigan/timeslip)
## Installation
Releases are published to [maven central][maven].
It can be included in your project by including the following in your project's build configuration.
```gradle
dependencies {
testImplementation 'com.hypercubetools:timeslip:0.1.0'
}
```
```maven
com.hypercubetools
timeslip
0.1.0
pom
```
## Detailed Documentation
Find more information about the API and how to use it on the [project website][project_website]
## Examples
```kotlin
fun formatTime(clock: Clock) =
DateTimeFormatter.ISO_TIME.withZone(clock.zone).format(clock.instant())
val constClock = TimeSlip.at(Instant.parse("2007-12-03T10:15:30.00Z"))
println(formatTime(constClock))
println(formatTime(constClock))
println(formatTime(constClock))
// 10:15:30Z
// 10:15:30Z
// 10:15:30Z
val tickingClock = TimeSlip.startAt(Instant.parse("2007-12-03T10:15:30.00Z"))
println(formatTime(tickingClock))
println(formatTime(tickingClock))
println(formatTime(tickingClock))
// 10:15:30Z
// 10:15:31Z
// 10:15:32Z
val ticking2MinClock = TimeSlip.startAt(
Instant.parse("2007-12-03T10:15:30.00Z"),
tickAmount = Duration.ofMinutes(2)
)
println(formatTime(ticking2MinClock))
println(formatTime(ticking2MinClock))
println(formatTime(ticking2MinClock))
// 10:15:30Z
// 10:17:30Z
// 10:19:30Z
val sequenceClock = TimeSlip.sequence {
first(Instant.parse("2007-12-03T10:15:30.00Z"))
then(Instant.parse("2007-12-03T10:16:00.00Z"), Instant.parse("2007-12-03T10:17:00.00Z"))
}
println(formatTime(sequenceClock))
println(formatTime(sequenceClock))
println(formatTime(sequenceClock))
// 10:15:30Z
// 10:16:00Z
// 10:17:00Z
```
[ci]: https://github.com/plannigan/timeslip/actions
[maven]: https://mvnrepository.com/artifact/com.hypercubetools/timeslip
[project_website]: https://timeslip.hypercubetools.com/