Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/trickl/clock
Browse files Browse the repository at this point in the history
  • Loading branch information
trickl committed Mar 30, 2019
2 parents 49aa05a + e0f6635 commit b11fac1
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
[![Test Coverage](https://api.codeclimate.com/v1/badges/6039371d2409365c76dc/test_coverage)](https://codeclimate.com/github/trickl/clock/test_coverage)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)

A set of java.time.Clock implementations with more useful functionality.
A set of [java.time.Clock](https://docs.oracle.com/javase/8/docs/api/java/time/Clock.html) 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.
Expand Down Expand Up @@ -35,5 +35,25 @@ mvn clean build
## Examples

### Mutable Clock

```
MutableClock mutableClock = MutableClock.at(clockStart);
Duration adjustment = Duration.ofMinutes(5);
mutableClock.advance(adjustment);
assertEquals(clockStart.plus(adjustment), mutableClock.instant());
```
### Relative Clock
```
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());
```

0 comments on commit b11fac1

Please sign in to comment.