@@ -14,7 +14,6 @@ import kotlinx.datetime.internal.JSJoda.Instant as jtInstant
14
14
import kotlinx.datetime.internal.JSJoda.Duration as jtDuration
15
15
import kotlinx.datetime.internal.JSJoda.Clock as jtClock
16
16
import kotlinx.datetime.internal.JSJoda.ChronoUnit
17
- import kotlin.math.nextTowards
18
17
import kotlin.math.truncate
19
18
20
19
@OptIn(ExperimentalTime ::class )
@@ -105,40 +104,14 @@ public actual fun Instant.plus(period: DateTimePeriod, timeZone: TimeZone): Inst
105
104
.run { if (days != 0 ) plusDays(days) as ZonedDateTime else this }
106
105
.run { if (hours != 0 ) plusHours(hours) else this }
107
106
.run { if (minutes != 0 ) plusMinutes(minutes) else this }
108
- .run { plusSecondsFix (seconds) }
109
- .run { plusNanosFix (nanoseconds) }
107
+ .run { if (seconds != 0L ) plusSeconds(seconds.toDouble()) else this }
108
+ .run { if (nanoseconds != 0L ) plusNanos(nanoseconds.toDouble()) else this }
110
109
}.toInstant().let (::Instant )
111
110
} catch (e: Throwable ) {
112
111
if (e.isJodaDateTimeException()) throw DateTimeArithmeticException (e)
113
112
throw e
114
113
}
115
114
116
- // workaround for https://github.com/js-joda/js-joda/issues/431
117
- private fun ZonedDateTime.plusSecondsFix (seconds : Long ): ZonedDateTime {
118
- val value = seconds.toDouble()
119
- return when {
120
- value == 0.0 -> this
121
- (value.unsafeCast<Int >() or 0 ) != 0 -> plusSeconds(value)
122
- else -> {
123
- val valueLittleLess = value.nextTowards(0.0 )
124
- plusSeconds(valueLittleLess).plusSeconds(value - valueLittleLess)
125
- }
126
- }
127
- }
128
-
129
- // workaround for https://github.com/js-joda/js-joda/issues/431
130
- private fun ZonedDateTime.plusNanosFix (nanoseconds : Long ): ZonedDateTime {
131
- val value = nanoseconds.toDouble()
132
- return when {
133
- value == 0.0 -> this
134
- (value.unsafeCast<Int >() or 0 ) != 0 -> plusNanos(value)
135
- else -> {
136
- val valueLittleLess = value.nextTowards(0.0 )
137
- plusNanos(valueLittleLess).plusNanos(value - valueLittleLess)
138
- }
139
- }
140
- }
141
-
142
115
private fun Instant.atZone (zone : TimeZone ): ZonedDateTime = value.atZone(zone.zoneId)
143
116
private fun jtInstant.checkZone (zone : TimeZone ): jtInstant = apply { atZone(zone.zoneId) }
144
117
0 commit comments