Skip to content

Instantly share code, notes, and snippets.

@lukestewart13
Created April 11, 2017 17:16
Show Gist options
  • Save lukestewart13/38ddba6e7afc1aa01ebc188dc8af2378 to your computer and use it in GitHub Desktop.
Save lukestewart13/38ddba6e7afc1aa01ebc188dc8af2378 to your computer and use it in GitHub Desktop.
NanoClock
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