A set of java.time.Clock implementations with more useful functionality.
- MutableClock - A version of FixedClock with a mutable time.
- RelativeClock - An adjustable clock that time keeps using a relative clock, but can be stopped, started and run at variable speeds.
To install from Maven Central:
<dependency>
<groupId>com.github.trickl</groupId>
<artifactId>clock</artifactId>
<version>0.1.1</version>
</dependency>
See the Junit tests for usage
To download the library into a folder called "clock" run
git clone https://github.com/trickl/clock.git
To build the library run
mvn clean build
MutableClock mutableClock = MutableClock.at(clockStart);
Duration adjustment = Duration.ofMinutes(5);
mutableClock.advance(adjustment);
assertEquals(clockStart.plus(adjustment), mutableClock.instant());
RelativeClock relativeClock = RelativeClock.standard()
.withReferenceClock(referenceClock);
relativeClock.setSpeed(3);
referenceClock.advance(Duration.ofMinutes(3));
relativeClock.setSpeed(5);
referenceClock.advance(Duration.ofMinutes(5));
relativeClock.setSpeed(7);
referenceClock.advance(Duration.ofMinutes(7));
Instant expectedTime = referenceClockStart.plus(Duration.ofMinutes(83));
assertEquals(expectedTime, relativeClock.instant());