From b20251623c01c4898e08984cb879cbea78c38a8a Mon Sep 17 00:00:00 2001 From: Dmitry Khalanskiy Date: Fri, 18 Oct 2024 12:27:11 +0200 Subject: [PATCH 1/3] Deprecate Clock.asTimeSource Fixes #372 --- core/common/src/Clock.kt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/core/common/src/Clock.kt b/core/common/src/Clock.kt index e9cd9137..b018cf45 100644 --- a/core/common/src/Clock.kt +++ b/core/common/src/Clock.kt @@ -77,8 +77,11 @@ public fun Clock.todayIn(timeZone: TimeZone): LocalDate = * because [Clock.System] is not well suited for measuring time intervals. * Please only use this conversion function on the [Clock] instances that are fully controlled programmatically. */ -@ExperimentalTime +@Deprecated("This function is deprecated because Clock.System.asTimeSource " + + "can be confused with TimeSource.Monotonic, which are very different. " + + "See https://github.com/Kotlin/kotlinx-datetime/issues/372", level = DeprecationLevel.ERROR) public fun Clock.asTimeSource(): TimeSource.WithComparableMarks = object : TimeSource.WithComparableMarks { + @ExperimentalTime override fun markNow(): ComparableTimeMark = InstantTimeMark(now(), this@asTimeSource) } From c87552ffea86d72270255f0d8c4765fc068be3b5 Mon Sep 17 00:00:00 2001 From: Dmitry Khalanskiy Date: Fri, 18 Oct 2024 12:28:01 +0200 Subject: [PATCH 2/3] Suppress deprecations in tests --- core/common/test/ClockTimeSourceTest.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/common/test/ClockTimeSourceTest.kt b/core/common/test/ClockTimeSourceTest.kt index 561cd222..b6bfe6c1 100644 --- a/core/common/test/ClockTimeSourceTest.kt +++ b/core/common/test/ClockTimeSourceTest.kt @@ -11,7 +11,7 @@ import kotlin.time.* import kotlin.time.Duration.Companion.days import kotlin.time.Duration.Companion.nanoseconds -@OptIn(ExperimentalTime::class) +@Suppress("DEPRECATION_ERROR") class ClockTimeSourceTest { @Test fun arithmetic() { From 2d71a294e9f2973d2975fde400f5e83f29ef7972 Mon Sep 17 00:00:00 2001 From: Dmitry Khalanskiy Date: Wed, 30 Oct 2024 11:56:41 +0100 Subject: [PATCH 3/3] Make the deprecation a warning --- core/common/src/Clock.kt | 3 ++- core/common/test/ClockTimeSourceTest.kt | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/core/common/src/Clock.kt b/core/common/src/Clock.kt index b018cf45..2fcc3d67 100644 --- a/core/common/src/Clock.kt +++ b/core/common/src/Clock.kt @@ -77,9 +77,10 @@ public fun Clock.todayIn(timeZone: TimeZone): LocalDate = * because [Clock.System] is not well suited for measuring time intervals. * Please only use this conversion function on the [Clock] instances that are fully controlled programmatically. */ +@ExperimentalTime @Deprecated("This function is deprecated because Clock.System.asTimeSource " + "can be confused with TimeSource.Monotonic, which are very different. " + - "See https://github.com/Kotlin/kotlinx-datetime/issues/372", level = DeprecationLevel.ERROR) + "See https://github.com/Kotlin/kotlinx-datetime/issues/372", level = DeprecationLevel.WARNING) public fun Clock.asTimeSource(): TimeSource.WithComparableMarks = object : TimeSource.WithComparableMarks { @ExperimentalTime override fun markNow(): ComparableTimeMark = InstantTimeMark(now(), this@asTimeSource) diff --git a/core/common/test/ClockTimeSourceTest.kt b/core/common/test/ClockTimeSourceTest.kt index b6bfe6c1..17882ae6 100644 --- a/core/common/test/ClockTimeSourceTest.kt +++ b/core/common/test/ClockTimeSourceTest.kt @@ -11,7 +11,8 @@ import kotlin.time.* import kotlin.time.Duration.Companion.days import kotlin.time.Duration.Companion.nanoseconds -@Suppress("DEPRECATION_ERROR") +@OptIn(ExperimentalTime::class) +@Suppress("DEPRECATION") class ClockTimeSourceTest { @Test fun arithmetic() {