Created
April 11, 2017 17:16
-
-
Save lukestewart13/38ddba6e7afc1aa01ebc188dc8af2378 to your computer and use it in GitHub Desktop.
NanoClock
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.time.{Clock, Instant, ZoneId} | |
class NanoClock(private val clock: Clock) extends Clock { | |
def this() { this(Clock.systemUTC) } | |
private val initialInstant = clock.instant | |
private val initialNanos = System.nanoTime | |
override def getZone: ZoneId = clock.getZone | |
override def instant: Instant = initialInstant.plusNanos(System.nanoTime - initialNanos) | |
override def withZone(zone: ZoneId): Clock = new NanoClock(clock.withZone(zone)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment