Skip to content

Commit a9fe69f

Browse files
committed
Address the review
1 parent a7b7a49 commit a9fe69f

File tree

4 files changed

+9
-11
lines changed

4 files changed

+9
-11
lines changed

core/common/test/InstantTest.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -559,6 +559,12 @@ class InstantRangeTest {
559559
assertArithmeticFails("$instant") { instant.plus(Long.MAX_VALUE, DateTimeUnit.YEAR, UTC) }
560560
assertArithmeticFails("$instant") { instant.plus(Long.MIN_VALUE, DateTimeUnit.YEAR, UTC) }
561561
}
562+
for (instant in smallInstants) {
563+
instant.plus(2 * Int.MAX_VALUE.toLong(), DateTimeUnit.DAY, UTC)
564+
instant.plus(2 * Int.MIN_VALUE.toLong(), DateTimeUnit.DAY, UTC)
565+
instant.plus(2 * Int.MAX_VALUE.toLong(), DateTimeUnit.MONTH, UTC)
566+
instant.plus(2 * Int.MIN_VALUE.toLong(), DateTimeUnit.MONTH, UTC)
567+
}
562568
// Overflowing a LocalDateTime in input
563569
maxValidInstant.plus(-1, DateTimeUnit.NANOSECOND, UTC)
564570
minValidInstant.plus(1, DateTimeUnit.NANOSECOND, UTC)

core/commonKotlin/src/Instant.kt

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ private fun Instant.check(zone: TimeZone): Instant = [email protected] {
192192
public actual fun Instant.plus(period: DateTimePeriod, timeZone: TimeZone): Instant = try {
193193
with(period) {
194194
val withDate = toZonedDateTimeFailing(timeZone)
195-
.run { if (totalMonths != 0L) plus(totalMonths.toLong(), DateTimeUnit.MONTH) else this }
195+
.run { if (totalMonths != 0L) plus(totalMonths, DateTimeUnit.MONTH) else this }
196196
.run { if (days != 0) plus(days.toLong(), DateTimeUnit.DAY) else this }
197197
withDate.toInstant()
198198
.run { if (totalNanoseconds != 0L) plus(0, totalNanoseconds).check(timeZone) else this }
@@ -212,11 +212,8 @@ public actual fun Instant.minus(value: Int, unit: DateTimeUnit, timeZone: TimeZo
212212
plus(-value.toLong(), unit, timeZone)
213213
public actual fun Instant.plus(value: Long, unit: DateTimeUnit, timeZone: TimeZone): Instant = try {
214214
when (unit) {
215-
is DateTimeUnit.DateBased -> {
216-
if (value < Int.MIN_VALUE || value > Int.MAX_VALUE)
217-
throw ArithmeticException("Can't add a Long date-based value, as it would cause an overflow")
215+
is DateTimeUnit.DateBased ->
218216
toZonedDateTimeFailing(timeZone).plus(value, unit).toInstant()
219-
}
220217
is DateTimeUnit.TimeBased ->
221218
check(timeZone).plus(value, unit).check(timeZone)
222219
}

core/commonKotlin/src/TimeZone.kt

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,7 @@ public actual open class TimeZone internal constructor() {
2121
public actual fun currentSystemDefault(): TimeZone {
2222
// TODO: probably check if currentSystemDefault name is parseable as FixedOffsetTimeZone?
2323
val (name, zone) = currentSystemDefaultZone()
24-
return if (zone == null) {
25-
of(name)
26-
} else {
27-
zone
28-
}
24+
return zone ?: of(name)
2925
}
3026

3127
public actual val UTC: FixedOffsetTimeZone = UtcOffset.ZERO.asTimeZone()

core/wasmJs/src/PlatformSpecifics.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
*/
55
package kotlinx.datetime.internal
66

7-
import kotlinx.datetime.internal.JSJoda.ZoneId
87
import kotlinx.datetime.internal.JSJoda.ZoneRulesProvider
98
import kotlin.js.unsafeCast
109

0 commit comments

Comments
 (0)