|
3 | 3 | * Use of this source code is governed by the Apache 2.0 License that can be found in the LICENSE.txt file.
|
4 | 4 | */
|
5 | 5 |
|
6 |
| -package kotlinx.datetime |
| 6 | +package kotlinx.time |
7 | 7 |
|
8 | 8 | import kotlin.time.*
|
9 | 9 |
|
@@ -59,70 +59,3 @@ public interface Clock {
|
59 | 59 |
|
60 | 60 | }
|
61 | 61 | }
|
62 |
| - |
63 |
| -/** |
64 |
| - * Returns the current date at the given [time zone][timeZone], according to [this Clock][this]. |
65 |
| - * |
66 |
| - * The time zone is important because the current date is not the same in all time zones at the same instant. |
67 |
| - * |
68 |
| - * @sample kotlinx.datetime.test.samples.ClockSamples.todayIn |
69 |
| - */ |
70 |
| -public fun Clock.todayIn(timeZone: TimeZone): LocalDate = |
71 |
| - now().toLocalDateTime(timeZone).date |
72 |
| - |
73 |
| -/** |
74 |
| - * Returns a [TimeSource] that uses this [Clock] to mark a time instant and to find the amount of time elapsed since that mark. |
75 |
| - * |
76 |
| - * **Pitfall**: using this function with [Clock.System] is error-prone |
77 |
| - * because [Clock.System] is not well suited for measuring time intervals. |
78 |
| - * Please only use this conversion function on the [Clock] instances that are fully controlled programmatically. |
79 |
| - */ |
80 |
| -@ExperimentalTime |
81 |
| -public fun Clock.asTimeSource(): TimeSource.WithComparableMarks = object : TimeSource.WithComparableMarks { |
82 |
| - override fun markNow(): ComparableTimeMark = InstantTimeMark(now(), this@asTimeSource) |
83 |
| -} |
84 |
| - |
85 |
| -@ExperimentalTime |
86 |
| -private class InstantTimeMark(private val instant: Instant, private val clock: Clock) : ComparableTimeMark { |
87 |
| - override fun elapsedNow(): Duration = saturatingDiff(clock.now(), instant) |
88 |
| - |
89 |
| - override fun plus(duration: Duration): ComparableTimeMark = InstantTimeMark(instant.saturatingAdd(duration), clock) |
90 |
| - override fun minus(duration: Duration): ComparableTimeMark = InstantTimeMark(instant.saturatingAdd(-duration), clock) |
91 |
| - |
92 |
| - override fun minus(other: ComparableTimeMark): Duration { |
93 |
| - if (other !is InstantTimeMark || other.clock != this.clock) { |
94 |
| - throw IllegalArgumentException("Subtracting or comparing time marks from different time sources is not possible: $this and $other") |
95 |
| - } |
96 |
| - return saturatingDiff(this.instant, other.instant) |
97 |
| - } |
98 |
| - |
99 |
| - override fun equals(other: Any?): Boolean { |
100 |
| - return other is InstantTimeMark && this.clock == other.clock && this.instant == other.instant |
101 |
| - } |
102 |
| - |
103 |
| - override fun hashCode(): Int = instant.hashCode() |
104 |
| - |
105 |
| - override fun toString(): String = "InstantTimeMark($instant, $clock)" |
106 |
| - |
107 |
| - private fun Instant.isSaturated() = this == Instant.MAX || this == Instant.MIN |
108 |
| - private fun Instant.saturatingAdd(duration: Duration): Instant { |
109 |
| - if (isSaturated()) { |
110 |
| - if (duration.isInfinite() && duration.isPositive() != this.isDistantFuture) { |
111 |
| - throw IllegalArgumentException("Summing infinities of different signs") |
112 |
| - } |
113 |
| - return this |
114 |
| - } |
115 |
| - return this + duration |
116 |
| - } |
117 |
| - private fun saturatingDiff(instant1: Instant, instant2: Instant): Duration = when { |
118 |
| - instant1 == instant2 -> |
119 |
| - Duration.ZERO |
120 |
| - instant1.isSaturated() || instant2.isSaturated() -> |
121 |
| - (instant1 - instant2) * Double.POSITIVE_INFINITY |
122 |
| - else -> |
123 |
| - instant1 - instant2 |
124 |
| - } |
125 |
| -} |
126 |
| - |
127 |
| -@Deprecated("Use Clock.todayIn instead", ReplaceWith("this.todayIn(timeZone)"), DeprecationLevel.WARNING) |
128 |
| -public fun Clock.todayAt(timeZone: TimeZone): LocalDate = todayIn(timeZone) |
0 commit comments