Stabilize Duration, DurationUnit and related top-level functions KT-46784

Co-authored-by: Abduqodiri Qurbonzoda <abduqodiri.qurbonzoda@jetbrains.com>
This commit is contained in:
Ilya Gorbunov
2021-09-19 04:36:44 +03:00
committed by Space
parent ad18343413
commit 96611de344
12 changed files with 60 additions and 117 deletions
@@ -8,19 +8,17 @@
@file:kotlin.jvm.JvmPackageName("kotlin.time.jdk8")
package kotlin.time
import java.time.*
/**
* Converts [java.time.Duration][java.time.Duration] value to [kotlin.time.Duration][Duration] value.
*
* Durations less than 104 days are converted exactly, and durations greater than that can lose some precision
* due to rounding.
*/
@SinceKotlin("1.3")
@ExperimentalTime
@SinceKotlin("1.6")
@WasExperimental(ExperimentalTime::class)
@kotlin.internal.InlineOnly
public inline fun java.time.Duration.toKotlinDuration(): Duration =
Duration.seconds(this.seconds) + Duration.nanoseconds(this.nano)
this.seconds.toDuration(DurationUnit.SECONDS) + this.nano.toDuration(DurationUnit.NANOSECONDS)
/**
@@ -28,8 +26,8 @@ public inline fun java.time.Duration.toKotlinDuration(): Duration =
*
* Durations greater than [Long.MAX_VALUE] seconds are cut to that value.
*/
@SinceKotlin("1.3")
@ExperimentalTime
@SinceKotlin("1.6")
@WasExperimental(ExperimentalTime::class)
@kotlin.internal.InlineOnly
public inline fun Duration.toJavaDuration(): java.time.Duration =
toComponents { seconds, nanoseconds -> java.time.Duration.ofSeconds(seconds, nanoseconds.toLong()) }
@@ -3,7 +3,6 @@
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
@file:OptIn(ExperimentalTime::class)
package kotlin.jdk8.time.test
import kotlin.random.Random