Skip to content

Commit

Permalink
Merge pull request #61 from isaacl/fixNanos
Browse files Browse the repository at this point in the history
Update time.nowNanos()
  • Loading branch information
ornicar authored Sep 22, 2024
2 parents 10e1db7 + 8ab1c63 commit f8106dc
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 @@ -98,12 +98,17 @@ object time:

inline def nowDateTime: LocalDateTime = LocalDateTime.now(utc_)
inline def nowInstant: Instant = Instant.now()
inline def nowNanos: Long = System.nanoTime()
inline def nowMillis: Long = System.currentTimeMillis()
inline def nowCentis: Long = nowMillis / 10L
inline def nowTenths: Long = nowMillis / 100L
inline def nowSeconds: Int = (nowMillis / 1000L).toInt // Guaranteed to not overflow until 2038

/** 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 f8106dc

Please sign in to comment.