Skip to content

Commit

Permalink
Update time.nowNanos()
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
isaacl committed Sep 21, 2024
1 parent 15826a2 commit 8ab1c63
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion core/src/main/scala/time.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 8ab1c63

Please sign in to comment.