Skip to content

Commit 5dcb6e2

Browse files
committed
Update js-joda version and remove a workaround
1 parent c3792e5 commit 5dcb6e2

File tree

2 files changed

+3
-34
lines changed

2 files changed

+3
-34
lines changed

core/build.gradle.kts

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
/*
2-
* Copyright 2019-2020 JetBrains s.r.o.
3-
* Use of this source code is governed by the Apache 2.0 License that can be found in the LICENSE.txt file.
4-
*/
51
import java.net.URL
62
import javax.xml.parsers.DocumentBuilderFactory
73

@@ -173,7 +169,7 @@ kotlin {
173169
val jsMain by getting {
174170
dependencies {
175171
api("org.jetbrains.kotlin:kotlin-stdlib-js")
176-
implementation(npm("@js-joda/core", "3.0.0"))
172+
implementation(npm("@js-joda/core", "3.1.0"))
177173
}
178174
}
179175

core/jsMain/src/Instant.kt

+2-29
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import kotlinx.datetime.internal.JSJoda.Instant as jtInstant
1414
import kotlinx.datetime.internal.JSJoda.Duration as jtDuration
1515
import kotlinx.datetime.internal.JSJoda.Clock as jtClock
1616
import kotlinx.datetime.internal.JSJoda.ChronoUnit
17-
import kotlin.math.nextTowards
1817
import kotlin.math.truncate
1918

2019
@OptIn(ExperimentalTime::class)
@@ -105,40 +104,14 @@ public actual fun Instant.plus(period: DateTimePeriod, timeZone: TimeZone): Inst
105104
.run { if (days != 0) plusDays(days) as ZonedDateTime else this }
106105
.run { if (hours != 0) plusHours(hours) else this }
107106
.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 }
110109
}.toInstant().let(::Instant)
111110
} catch (e: Throwable) {
112111
if (e.isJodaDateTimeException()) throw DateTimeArithmeticException(e)
113112
throw e
114113
}
115114

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-
142115
private fun Instant.atZone(zone: TimeZone): ZonedDateTime = value.atZone(zone.zoneId)
143116
private fun jtInstant.checkZone(zone: TimeZone): jtInstant = apply { atZone(zone.zoneId) }
144117

0 commit comments

Comments
 (0)