@@ -76,11 +76,6 @@ public fun String.toInstant(): Instant = Instant.parse(this)
76
76
*/
77
77
public expect fun Instant.plus (period : DateTimePeriod , zone : TimeZone ): Instant
78
78
79
- /* *
80
- * @throws DateTimeArithmeticException if this value or the result is too large to fit in [LocalDateTime].
81
- */
82
- internal expect fun Instant.plus (value : Int , unit : CalendarUnit , zone : TimeZone ): Instant
83
-
84
79
/* *
85
80
* @throws DateTimeArithmeticException if this value or the result is too large to fit in [LocalDateTime].
86
81
*/
@@ -97,7 +92,7 @@ public expect fun Instant.periodUntil(other: Instant, zone: TimeZone): DateTimeP
97
92
*
98
93
* @throws DateTimeArithmeticException if this [Instant] or [other] is too large to fit in [LocalDateTime].
99
94
*/
100
- internal expect fun Instant.until (other : Instant , unit : CalendarUnit , zone : TimeZone ): Long
95
+ public expect fun Instant.until (other : Instant , unit : DateTimeUnit , zone : TimeZone ): Long
101
96
102
97
/* *
103
98
* The return value is clamped to [Int.MAX_VALUE] or [Int.MIN_VALUE] if the result would otherwise cause an arithmetic
@@ -106,7 +101,7 @@ internal expect fun Instant.until(other: Instant, unit: CalendarUnit, zone: Time
106
101
* @throws DateTimeArithmeticException if this [Instant] or [other] is too large to fit in [LocalDateTime].
107
102
*/
108
103
public fun Instant.daysUntil (other : Instant , zone : TimeZone ): Int =
109
- until(other, CalendarUnit .DAY , zone).clampToInt()
104
+ until(other, DateTimeUnit .DAY , zone).clampToInt()
110
105
111
106
/* *
112
107
* The return value is clamped to [Int.MAX_VALUE] or [Int.MIN_VALUE] if the result would otherwise cause an arithmetic
@@ -115,7 +110,7 @@ public fun Instant.daysUntil(other: Instant, zone: TimeZone): Int =
115
110
* @throws DateTimeArithmeticException if this [Instant] or [other] is too large to fit in [LocalDateTime].
116
111
*/
117
112
public fun Instant.monthsUntil (other : Instant , zone : TimeZone ): Int =
118
- until(other, CalendarUnit .MONTH , zone).clampToInt()
113
+ until(other, DateTimeUnit .MONTH , zone).clampToInt()
119
114
120
115
/* *
121
116
* The return value is clamped to [Int.MAX_VALUE] or [Int.MIN_VALUE] if the result would otherwise cause an arithmetic
@@ -124,7 +119,7 @@ public fun Instant.monthsUntil(other: Instant, zone: TimeZone): Int =
124
119
* @throws DateTimeArithmeticException if this [Instant] or [other] is too large to fit in [LocalDateTime].
125
120
*/
126
121
public fun Instant.yearsUntil (other : Instant , zone : TimeZone ): Int =
127
- until(other, CalendarUnit .YEAR , zone).clampToInt()
122
+ until(other, DateTimeUnit .YEAR , zone).clampToInt()
128
123
129
124
// TODO: move to internal utils
130
125
internal fun Long.clampToInt (): Int =
@@ -133,15 +128,24 @@ internal fun Long.clampToInt(): Int =
133
128
public fun Instant.minus (other : Instant , zone : TimeZone ): DateTimePeriod = other.periodUntil(this , zone)
134
129
135
130
136
-
131
+ /* *
132
+ * @throws DateTimeArithmeticException if this value or the result is too large to fit in [LocalDateTime].
133
+ */
137
134
public fun Instant.plus (unit : DateTimeUnit , zone : TimeZone ): Instant =
138
135
plus(unit.calendarScale, unit.calendarUnit, zone)
136
+
137
+ // TODO: safeMultiply
138
+ /* *
139
+ * @throws DateTimeArithmeticException if this value or the result is too large to fit in [LocalDateTime].
140
+ */
139
141
public fun Instant.plus (value : Int , unit : DateTimeUnit , zone : TimeZone ): Instant =
140
142
plus(value * unit.calendarScale, unit.calendarUnit, zone)
143
+
144
+ /* *
145
+ * @throws DateTimeArithmeticException if this value or the result is too large to fit in [LocalDateTime].
146
+ */
141
147
public fun Instant.plus (value : Long , unit : DateTimeUnit , zone : TimeZone ): Instant =
142
148
plus(value * unit.calendarScale, unit.calendarUnit, zone)
143
149
144
- public fun Instant.until (other : Instant , unit : DateTimeUnit , zone : TimeZone ): Long =
145
- until(other, unit.calendarUnit, zone) / unit.calendarScale
146
150
147
151
public fun Instant.minus (other : Instant , unit : DateTimeUnit , zone : TimeZone ): Long = other.until(this , unit, zone)
0 commit comments