From 8ab1c63ae99e6eff4600667469b4db4fef0cdeae Mon Sep 17 00:00:00 2001 From: Isaac Levy Date: Sat, 21 Sep 2024 10:08:05 -0400 Subject: [PATCH] Update time.nowNanos() System.nanoTime() is relative to some point in time which changes each run. It's useful only to track elapsed nanos, not to measure a wall clock. --- core/src/main/scala/time.scala | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/core/src/main/scala/time.scala b/core/src/main/scala/time.scala index c4a6d64..006db8f 100644 --- a/core/src/main/scala/time.scala +++ b/core/src/main/scala/time.scala @@ -78,12 +78,17 @@ object time: inline def nowDateTime: LocalDateTime = LocalDateTime.now() inline def nowInstant: Instant = Instant.now() - inline def nowNanos: Long = System.nanoTime() inline def nowMillis: Long = System.currentTimeMillis() inline def nowCentis: Long = nowMillis / 10 inline def nowTenths: Long = nowMillis / 100 inline def nowSeconds: Int = (nowMillis / 1000).toInt + /** Relative to some arbitrary point in time. + * + * Useful only in comparisons to self, such as measuring time intervals. + */ + inline def nowNanosRel: Long = System.nanoTime() + def instantOf(year: Int, month: Int, dayOfMonth: Int, hour: Int, minute: Int) = java.time.LocalDateTime.of(year, month, dayOfMonth, hour, minute).instant