Suggest duration static factories instead of number extension properties

Introduce Duration companion functions to convert numbers to Duration.
Deprecate number extension properties and propose to use these
new functions instead.
This commit is contained in:
Ilya Gorbunov
2021-02-12 04:22:43 +03:00
committed by ilya-g
parent ca99fc4fed
commit a7fda66fa1
12 changed files with 523 additions and 191 deletions
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
@@ -37,7 +37,7 @@ internal class HrTimeSource(val process: Process) : TimeSource {
override fun markNow(): TimeMark = object : TimeMark() {
val startedAt = process.hrtime()
override fun elapsedNow(): Duration =
process.hrtime(startedAt).let { (seconds, nanos) -> seconds.seconds + nanos.nanoseconds }
process.hrtime(startedAt).let { (seconds, nanos) -> Duration.seconds(seconds) + Duration.nanoseconds(nanos) }
}
override fun toString(): String = "TimeSource(process.hrtime())"