Skip to content

Commit 1123e14

Browse files
authored
Deprecate Clock.asTimeSource (#450)
Fixes #372
1 parent 85c1ccd commit 1123e14

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

core/common/src/Clock.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,11 @@ public fun Clock.todayIn(timeZone: TimeZone): LocalDate =
7878
* Please only use this conversion function on the [Clock] instances that are fully controlled programmatically.
7979
*/
8080
@ExperimentalTime
81+
@Deprecated("This function is deprecated because Clock.System.asTimeSource " +
82+
"can be confused with TimeSource.Monotonic, which are very different. " +
83+
"See https://github.com/Kotlin/kotlinx-datetime/issues/372", level = DeprecationLevel.WARNING)
8184
public fun Clock.asTimeSource(): TimeSource.WithComparableMarks = object : TimeSource.WithComparableMarks {
85+
@ExperimentalTime
8286
override fun markNow(): ComparableTimeMark = InstantTimeMark(now(), this@asTimeSource)
8387
}
8488

core/common/test/ClockTimeSourceTest.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import kotlin.time.Duration.Companion.nanoseconds
1313
import kotlin.time.Duration.Companion.seconds
1414

1515
@OptIn(ExperimentalTime::class)
16+
@Suppress("DEPRECATION")
1617
class ClockTimeSourceTest {
1718
@Test
1819
fun arithmetic() {

0 commit comments

Comments
 (0)