Bring back Duration construction extensions KT-46229

Return the extension properties for constructing Duration from numbers,
but this time place them in Duration.Companion rather than on top-level.

- provide the new set of construction extension properties
  in companion of Duration
- leave top-level extension properties experimental,
  increase their deprecation level to ERROR,
  propose the extension properties in companion instead.
- leave Duration companion static factory functions experimental,
  deprecate them and propose the extension properties in companion instead.
This commit is contained in:
Ilya Gorbunov
2021-09-19 04:50:41 +03:00
committed by Space
parent 96611de344
commit 21a9198fff
10 changed files with 818 additions and 288 deletions
+11 -9
View File
@@ -8,6 +8,8 @@ package test.time
import kotlin.test.*
import kotlin.time.*
import kotlin.time.Duration.Companion.milliseconds
import kotlin.time.Duration.Companion.nanoseconds
class TimeMarkTest {
@@ -27,19 +29,19 @@ class TimeMarkTest {
}
val mark = timeSource.markNow()
val markFuture1 = (mark + Duration.milliseconds(1)).apply { assertHasPassed(false) }
val markFuture2 = (mark - Duration.milliseconds((-1))).apply { assertHasPassed(false) }
val markFuture1 = (mark + 1.milliseconds).apply { assertHasPassed(false) }
val markFuture2 = (mark - (-1).milliseconds).apply { assertHasPassed(false) }
val markPast1 = (mark - Duration.milliseconds(1)).apply { assertHasPassed(true) }
val markPast2 = (markFuture1 + Duration.milliseconds((-2))).apply { assertHasPassed(true) }
val markPast1 = (mark - 1.milliseconds).apply { assertHasPassed(true) }
val markPast2 = (markFuture1 + (-2).milliseconds).apply { assertHasPassed(true) }
timeSource += Duration.nanoseconds(500_000)
timeSource += 500_000.nanoseconds
val elapsed = mark.elapsedNow()
val elapsedFromFuture = elapsed - Duration.milliseconds(1)
val elapsedFromPast = elapsed + Duration.milliseconds(1)
val elapsedFromFuture = elapsed - 1.milliseconds
val elapsedFromPast = elapsed + 1.milliseconds
assertEquals(Duration.milliseconds(0.5), elapsed)
assertEquals(0.5.milliseconds, elapsed)
assertEquals(elapsedFromFuture, markFuture1.elapsedNow())
assertEquals(elapsedFromFuture, markFuture2.elapsedNow())
@@ -49,7 +51,7 @@ class TimeMarkTest {
markFuture1.assertHasPassed(false)
markPast1.assertHasPassed(true)
timeSource += Duration.milliseconds(1)
timeSource += 1.milliseconds
markFuture1.assertHasPassed(true)
markPast1.assertHasPassed(true)