Skip to content

Commit 8cdb53f

Browse files
committed
CODEREVIEW AMMEND
1 parent 074bcc5 commit 8cdb53f

15 files changed

+61
-69
lines changed

core/build.gradle.kts

+7-7
Original file line numberDiff line numberDiff line change
@@ -202,41 +202,41 @@ kotlin {
202202
}
203203
}
204204

205-
val jsAndWasmSharedMain by creating {
205+
val commonJsMain by creating {
206206
dependsOn(commonMain.get())
207207
dependencies {
208208
api("org.jetbrains.kotlinx:kotlinx-serialization-core:$serializationVersion")
209209
implementation(npm("@js-joda/core", "3.2.0"))
210210
}
211211
}
212212

213-
val jsAndWasmSharedTest by creating {
213+
val commonJsTest by creating {
214214
dependsOn(commonTest.get())
215215
dependencies {
216216
implementation(npm("@js-joda/timezone", "2.3.0"))
217217
}
218218
}
219219

220220
val jsMain by getting {
221-
dependsOn(jsAndWasmSharedMain)
221+
dependsOn(commonJsMain)
222222
dependencies {
223223
api("org.jetbrains.kotlin:kotlin-stdlib-js")
224224
}
225225
}
226226

227227
val jsTest by getting {
228-
dependsOn(jsAndWasmSharedTest)
228+
dependsOn(commonJsTest)
229229
}
230230

231231
val wasmJsMain by getting {
232-
dependsOn(jsAndWasmSharedMain)
232+
dependsOn(commonJsMain)
233233
dependencies {
234234
api("org.jetbrains.kotlin:kotlin-stdlib-wasm-js")
235235
}
236236
}
237237

238238
val wasmJsTest by getting {
239-
dependsOn(jsAndWasmSharedTest)
239+
dependsOn(commonJsTest)
240240
}
241241

242242
val nativeMain by getting {
@@ -418,7 +418,7 @@ tasks.withType<AbstractDokkaLeafTask>().configureEach {
418418

419419
// Disable intermediate sourceSet compilation because we do not need js-wasmJs artifact
420420
tasks.configureEach {
421-
if (name == "compileJsAndWasmSharedMainKotlinMetadata") {
421+
if (name == "compileCommonJsMainKotlinMetadata") {
422422
enabled = false
423423
}
424424
}

core/jsAndWasmShared/src/Instant.kt renamed to core/commonJs/src/Instant.kt

+22-27
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import kotlinx.datetime.internal.JodaTimeInstant as jtInstant
99
import kotlinx.datetime.internal.JodaTimeOffsetDateTime as jtOffsetDateTime
1010
import kotlinx.datetime.internal.JodaTimeDuration as jtDuration
1111
import kotlinx.datetime.internal.JodaTimeClock as jtClock
12+
import kotlinx.datetime.internal.JodaTimeChronoUnit as jtChronoUnit
1213
import kotlinx.datetime.internal.safeAdd
1314
import kotlinx.datetime.internal.*
1415
import kotlinx.datetime.serializers.InstantIso8601Serializer
@@ -30,9 +31,7 @@ public actual class Instant internal constructor(internal val value: jtInstant)
3031

3132
public actual operator fun plus(duration: Duration): Instant = duration.toComponents { seconds, nanoseconds ->
3233
return try {
33-
// jsTry {
34-
Instant(plusFix(seconds.toDouble(), nanoseconds))
35-
// }
34+
Instant(plusFix(seconds.toDouble(), nanoseconds))
3635
} catch (e: Throwable) {
3736
if (!e.isJodaDateTimeException()) throw e
3837
if (duration.isPositive()) MAX else MIN
@@ -41,8 +40,8 @@ public actual class Instant internal constructor(internal val value: jtInstant)
4140

4241
internal fun plusFix(seconds: Double, nanos: Int): jtInstant {
4342
val newSeconds = value.epochSecond() + seconds
44-
val newNanos = (value.nano() + nanos).toInt()
45-
return jtInstant.ofEpochSecond(newSeconds, newNanos)
43+
val newNanos = value.nano() + nanos
44+
return jtInstant.ofEpochSecond(newSeconds, newNanos.toInt())
4645
}
4746

4847
public actual operator fun minus(duration: Duration): Instant = plus(-duration)
@@ -55,7 +54,7 @@ public actual class Instant internal constructor(internal val value: jtInstant)
5554
public actual override operator fun compareTo(other: Instant): Int = this.value.compareTo(other.value)
5655

5756
override fun equals(other: Any?): Boolean =
58-
(this === other) || (other is Instant && (this.value === other.value || this.value.equals(other.value)))
57+
(this === other) || (other is Instant && this.value == other.value)
5958

6059
override fun hashCode(): Int = value.hashCode()
6160

@@ -92,12 +91,12 @@ public actual class Instant internal constructor(internal val value: jtInstant)
9291
}
9392

9493
public actual fun fromEpochSeconds(epochSeconds: Long, nanosecondAdjustment: Long): Instant = try {
95-
/* Performing normalization here because otherwise this fails:
94+
/* Performing normalization here because otherwise this fails:
9695
assertEquals((Long.MAX_VALUE % 1_000_000_000).toInt(),
9796
Instant.fromEpochSeconds(0, Long.MAX_VALUE).nanosecondsOfSecond) */
98-
val secs = safeAdd(epochSeconds, nanosecondAdjustment.floorDiv(NANOS_PER_ONE.toLong()))
99-
val nos = nanosecondAdjustment.mod(NANOS_PER_ONE.toLong()).toInt()
100-
Instant(jtInstant.ofEpochSecond(secs.toDouble(), nos))
97+
val secs = safeAdd(epochSeconds, nanosecondAdjustment.floorDiv(NANOS_PER_ONE.toLong()))
98+
val nos = nanosecondAdjustment.mod(NANOS_PER_ONE.toLong()).toInt()
99+
Instant(jtInstant.ofEpochSecond(secs.toDouble(), nos))
101100
} catch (e: Throwable) {
102101
if (!e.isJodaDateTimeException() && e !is ArithmeticException) throw e
103102
if (epochSeconds > 0) MAX else MIN
@@ -123,12 +122,12 @@ public actual fun Instant.plus(period: DateTimePeriod, timeZone: TimeZone): Inst
123122
val thisZdt = this.value.atZone(timeZone.zoneId)
124123
with(period) {
125124
thisZdt
126-
.run { if (totalMonths != 0) plusMonths(totalMonths) else this }
127-
.run { if (days != 0) plusDays(days) else this }
128-
.run { if (hours != 0) plusHours(hours) else this }
129-
.run { if (minutes != 0) plusMinutes(minutes) else this }
130-
.run { if (seconds != 0) plusSeconds(seconds) else this }
131-
.run { if (nanoseconds != 0) plusNanos(nanoseconds.toDouble()) else this }
125+
.run { if (totalMonths != 0) plusMonths(totalMonths) else this }
126+
.run { if (days != 0) plusDays(days) else this }
127+
.run { if (hours != 0) plusHours(hours) else this }
128+
.run { if (minutes != 0) plusMinutes(minutes) else this }
129+
.run { if (seconds != 0) plusSeconds(seconds) else this }
130+
.run { if (nanoseconds != 0) plusNanos(nanoseconds.toDouble()) else this }
132131
}.toInstant().let(::Instant)
133132
} catch (e: Throwable) {
134133
if (e.isJodaDateTimeException()) throw DateTimeArithmeticException(e)
@@ -149,10 +148,8 @@ public actual fun Instant.plus(value: Long, unit: DateTimeUnit, timeZone: TimeZo
149148
is DateTimeUnit.TimeBased -> {
150149
plus(value, unit).value.checkZone(timeZone)
151150
}
152-
153151
is DateTimeUnit.DayBased ->
154152
thisZdt.plusDays(value.toDouble() * unit.days).toInstant()
155-
156153
is DateTimeUnit.MonthBased ->
157154
thisZdt.plusMonths(value.toDouble() * unit.months).toInstant()
158155
}.let(::Instant)
@@ -167,10 +164,8 @@ public actual fun Instant.plus(value: Int, unit: DateTimeUnit, timeZone: TimeZon
167164
when (unit) {
168165
is DateTimeUnit.TimeBased ->
169166
plus(value.toLong(), unit).value.checkZone(timeZone)
170-
171167
is DateTimeUnit.DayBased ->
172168
thisZdt.plusDays(value.toDouble() * unit.days).toInstant()
173-
174169
is DateTimeUnit.MonthBased ->
175170
thisZdt.plusMonths(value.toDouble() * unit.months).toInstant()
176171
}.let(::Instant)
@@ -201,9 +196,9 @@ public actual fun Instant.periodUntil(other: Instant, timeZone: TimeZone): DateT
201196
var thisZdt = this.value.atZone(timeZone.zoneId)
202197
val otherZdt = other.value.atZone(timeZone.zoneId)
203198

204-
val months = thisZdt.until(otherZdt, JodaTimeChronoUnit.MONTHS); thisZdt = thisZdt.plusMonths(months)
205-
val days = thisZdt.until(otherZdt, JodaTimeChronoUnit.DAYS); thisZdt = thisZdt.plusDays(days)
206-
val nanoseconds = thisZdt.until(otherZdt, JodaTimeChronoUnit.NANOS)
199+
val months = thisZdt.until(otherZdt, jtChronoUnit.MONTHS); thisZdt = thisZdt.plusMonths(months)
200+
val days = thisZdt.until(otherZdt, jtChronoUnit.DAYS); thisZdt = thisZdt.plusDays(days)
201+
val nanoseconds = thisZdt.until(otherZdt, jtChronoUnit.NANOS)
207202

208203
buildDateTimePeriod(months.toInt(), days.toInt(), nanoseconds.toLong())
209204
} catch (e: Throwable) {
@@ -213,10 +208,10 @@ public actual fun Instant.periodUntil(other: Instant, timeZone: TimeZone): DateT
213208
public actual fun Instant.until(other: Instant, unit: DateTimeUnit, timeZone: TimeZone): Long = try {
214209
val thisZdt = this.atZone(timeZone)
215210
val otherZdt = other.atZone(timeZone)
216-
when (unit) {
211+
when(unit) {
217212
is DateTimeUnit.TimeBased -> until(other, unit)
218-
is DateTimeUnit.DayBased -> (thisZdt.until(otherZdt, JodaTimeChronoUnit.DAYS) / unit.days).toLong()
219-
is DateTimeUnit.MonthBased -> (thisZdt.until(otherZdt, JodaTimeChronoUnit.MONTHS) / unit.months).toLong()
213+
is DateTimeUnit.DayBased -> (thisZdt.until(otherZdt, jtChronoUnit.DAYS) / unit.days).toLong()
214+
is DateTimeUnit.MonthBased -> (thisZdt.until(otherZdt, jtChronoUnit.MONTHS) / unit.months).toLong()
220215
}
221216
} catch (e: ArithmeticException) {
222217
if (this < other) Long.MAX_VALUE else Long.MIN_VALUE
@@ -225,4 +220,4 @@ public actual fun Instant.until(other: Instant, unit: DateTimeUnit, timeZone: Ti
225220
}
226221

227222
internal actual fun Instant.toStringWithOffset(offset: UtcOffset): String =
228-
jtOffsetDateTime.ofInstant(this.value, offset.zoneOffset).toString()
223+
jtOffsetDateTime.ofInstant(this.value, offset.zoneOffset).toString()

core/jsAndWasmShared/src/LocalDate.kt renamed to core/commonJs/src/LocalDate.kt

+9-9
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55

66
package kotlinx.datetime
77

8-
import kotlinx.datetime.internal.JodaTimeChronoUnit
98
import kotlinx.datetime.serializers.LocalDateIso8601Serializer
109
import kotlinx.serialization.Serializable
1110
import kotlinx.datetime.internal.JodaTimeLocalDate as jtLocalDate
11+
import kotlinx.datetime.internal.JodaTimeChronoUnit as jtChronoUnit
1212

1313
@Serializable(with = LocalDateIso8601Serializer::class)
1414
public actual class LocalDate internal constructor(internal val value: jtLocalDate) : Comparable<LocalDate> {
@@ -49,7 +49,7 @@ public actual class LocalDate internal constructor(internal val value: jtLocalDa
4949
public actual val dayOfYear: Int get() = value.dayOfYear()
5050

5151
override fun equals(other: Any?): Boolean =
52-
(this === other) || (other is LocalDate && (this.value === other.value || this.value.equals(other.value)))
52+
(this === other) || (other is LocalDate && this.value == other.value)
5353

5454
override fun hashCode(): Int = value.hashCode()
5555

@@ -81,8 +81,8 @@ private fun LocalDate.plusNumber(value: Number, unit: DateTimeUnit.DateBased): L
8181
public actual operator fun LocalDate.plus(period: DatePeriod): LocalDate = try {
8282
with(period) {
8383
return@with value
84-
.run { if (totalMonths != 0) plusMonths(totalMonths) else this }
85-
.run { if (days != 0) plusDays(days) else this }
84+
.run { if (totalMonths != 0) plusMonths(totalMonths) else this }
85+
.run { if (days != 0) plusDays(days) else this }
8686

8787
}.let(::LocalDate)
8888
} catch (e: Throwable) {
@@ -95,8 +95,8 @@ public actual operator fun LocalDate.plus(period: DatePeriod): LocalDate = try {
9595
public actual fun LocalDate.periodUntil(other: LocalDate): DatePeriod {
9696
var startD = this.value
9797
val endD = other.value
98-
val months = startD.until(endD, JodaTimeChronoUnit.MONTHS).toInt(); startD = startD.plusMonths(months)
99-
val days = startD.until(endD, JodaTimeChronoUnit.DAYS).toInt()
98+
val months = startD.until(endD, jtChronoUnit.MONTHS).toInt(); startD = startD.plusMonths(months)
99+
val days = startD.until(endD, jtChronoUnit.DAYS).toInt()
100100

101101
return DatePeriod(totalMonths = months, days)
102102
}
@@ -107,10 +107,10 @@ public actual fun LocalDate.until(other: LocalDate, unit: DateTimeUnit.DateBased
107107
}
108108

109109
public actual fun LocalDate.daysUntil(other: LocalDate): Int =
110-
this.value.until(other.value, JodaTimeChronoUnit.DAYS).toInt()
110+
this.value.until(other.value, jtChronoUnit.DAYS).toInt()
111111

112112
public actual fun LocalDate.monthsUntil(other: LocalDate): Int =
113-
this.value.until(other.value, JodaTimeChronoUnit.MONTHS).toInt()
113+
this.value.until(other.value, jtChronoUnit.MONTHS).toInt()
114114

115115
public actual fun LocalDate.yearsUntil(other: LocalDate): Int =
116-
this.value.until(other.value, JodaTimeChronoUnit.YEARS).toInt()
116+
this.value.until(other.value, jtChronoUnit.YEARS).toInt()

core/jsAndWasmShared/src/LocalDateTime.kt renamed to core/commonJs/src/LocalDateTime.kt

+2-3
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public actual class LocalDateTime internal constructor(internal val value: jtLoc
4242
public actual val time: LocalTime get() = LocalTime(value.toLocalTime())
4343

4444
override fun equals(other: Any?): Boolean =
45-
(this === other) || (other is LocalDateTime && this.value == other.value)
45+
(this === other) || (other is LocalDateTime && this.value == other.value)
4646

4747
override fun hashCode(): Int = value.hashCode()
4848

@@ -62,5 +62,4 @@ public actual class LocalDateTime internal constructor(internal val value: jtLoc
6262
internal actual val MAX: LocalDateTime = LocalDateTime(jtLocalDateTime.MAX)
6363
}
6464

65-
}
66-
65+
}

core/jsAndWasmShared/src/LocalTime.kt renamed to core/commonJs/src/LocalTime.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,4 @@ public actual class LocalTime internal constructor(internal val value: jtLocalTi
7070
internal actual val MIN: LocalTime = LocalTime(jtLocalTime.MIN)
7171
internal actual val MAX: LocalTime = LocalTime(jtLocalTime.MAX)
7272
}
73-
}
73+
}
File renamed without changes.

core/jsAndWasmShared/src/TimeZone.kt renamed to core/commonJs/src/TimeZone.kt

+12-9
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,19 @@
55
package kotlinx.datetime
66

77
import kotlinx.datetime.internal.*
8-
import kotlinx.datetime.internal.JodaTimeLocalDateTime
98
import kotlinx.datetime.internal.JodaTimeZoneId
9+
import kotlinx.datetime.internal.JodaTimeLocalDateTime as jtLocalDateTime
10+
import kotlinx.datetime.internal.JodaTimeZoneId as jtZoneId
11+
import kotlinx.datetime.internal.JodaTimeZoneOffset as jtZoneOffset
1012
import kotlinx.datetime.internal.getAvailableZoneIdsSet
1113
import kotlinx.datetime.serializers.*
12-
import kotlinx.datetime.internal.JodaTimeZoneOffset as jtZoneOffset
1314
import kotlinx.serialization.Serializable
1415

1516
@Serializable(with = TimeZoneSerializer::class)
16-
public actual open class TimeZone internal constructor(internal val zoneId: JodaTimeZoneId) {
17+
public actual open class TimeZone internal constructor(internal val zoneId: jtZoneId) {
1718
public actual val id: String get() = zoneId.id()
1819

20+
1921
// experimental member-extensions
2022
public actual fun Instant.toLocalDateTime(): LocalDateTime = toLocalDateTime(this@TimeZone)
2123
public actual fun LocalDateTime.toInstant(): Instant = toInstant(this@TimeZone)
@@ -28,11 +30,11 @@ public actual open class TimeZone internal constructor(internal val zoneId: Joda
2830
override fun toString(): String = zoneId.toString()
2931

3032
public actual companion object {
31-
public actual fun currentSystemDefault(): TimeZone = ofZone(JodaTimeZoneId.systemDefault())
33+
public actual fun currentSystemDefault(): TimeZone = ofZone(jtZoneId.systemDefault())
3234
public actual val UTC: FixedOffsetTimeZone = UtcOffset(jtZoneOffset.UTC).asTimeZone()
3335

3436
public actual fun of(zoneId: String): TimeZone = try {
35-
ofZone(JodaTimeZoneId.of(zoneId))
37+
ofZone(jtZoneId.of(zoneId))
3638
} catch (e: Throwable) {
3739
if (e.isJodaDateTimeException()) throw IllegalTimeZoneException(e)
3840
throw e
@@ -55,22 +57,23 @@ public actual open class TimeZone internal constructor(internal val zoneId: Joda
5557

5658
@Serializable(with = FixedOffsetTimeZoneSerializer::class)
5759
public actual class FixedOffsetTimeZone
58-
internal constructor(public actual val offset: UtcOffset, zoneId: JodaTimeZoneId): TimeZone(zoneId) {
60+
internal constructor(public actual val offset: UtcOffset, zoneId: jtZoneId): TimeZone(zoneId) {
5961
public actual constructor(offset: UtcOffset) : this(offset, offset.zoneOffset)
6062

6163
@Deprecated("Use offset.totalSeconds", ReplaceWith("offset.totalSeconds"))
6264
public actual val totalSeconds: Int get() = offset.totalSeconds
6365
}
6466

67+
6568
public actual fun Instant.toLocalDateTime(timeZone: TimeZone): LocalDateTime = try {
66-
JodaTimeLocalDateTime.ofInstant(this.value, timeZone.zoneId).let(::LocalDateTime)
69+
jtLocalDateTime.ofInstant(this.value, timeZone.zoneId).let(::LocalDateTime)
6770
} catch (e: Throwable) {
6871
if (e.isJodaDateTimeException()) throw DateTimeArithmeticException(e)
6972
throw e
7073
}
7174

7275
internal actual fun Instant.toLocalDateTime(offset: UtcOffset): LocalDateTime = try {
73-
JodaTimeLocalDateTime.ofInstant(this.value, offset.zoneOffset).let(::LocalDateTime)
76+
jtLocalDateTime.ofInstant(this.value, offset.zoneOffset).let(::LocalDateTime)
7477
} catch (e: Throwable) {
7578
if (e.isJodaDateTimeException()) throw DateTimeArithmeticException(e)
7679
throw e
@@ -87,4 +90,4 @@ public actual fun LocalDateTime.toInstant(offset: UtcOffset): Instant =
8790
this.value.toInstant(offset.zoneOffset).let(::Instant)
8891

8992
public actual fun LocalDate.atStartOfDayIn(timeZone: TimeZone): Instant =
90-
this.value.atStartOfDay(timeZone.zoneId).toInstant().let(::Instant)
93+
this.value.atStartOfDay(timeZone.zoneId).toInstant().let(::Instant)

core/jsAndWasmShared/src/UtcOffset.kt renamed to core/commonJs/src/UtcOffset.kt

+8-13
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,24 @@
55

66
package kotlinx.datetime
77

8-
import kotlinx.datetime.internal.JodaTimeZoneOffset
8+
import kotlinx.datetime.internal.JodaTimeZoneOffset as jtZoneOffset
99
import kotlinx.datetime.serializers.UtcOffsetSerializer
1010
import kotlinx.serialization.Serializable
1111

1212
@Serializable(with = UtcOffsetSerializer::class)
13-
public actual class UtcOffset internal constructor(internal val zoneOffset: JodaTimeZoneOffset) {
13+
public actual class UtcOffset internal constructor(internal val zoneOffset: jtZoneOffset) {
1414
public actual val totalSeconds: Int get() = zoneOffset.totalSeconds()
1515

1616
override fun hashCode(): Int = zoneOffset.hashCode()
17-
18-
override fun equals(other: Any?): Boolean =
19-
this === other || (other is UtcOffset && (this.zoneOffset === other.zoneOffset || this.zoneOffset.equals(other.zoneOffset)))
20-
17+
override fun equals(other: Any?): Boolean = other is UtcOffset && this.zoneOffset == other.zoneOffset
2118
override fun toString(): String = zoneOffset.toString()
2219

2320
public actual companion object {
2421

25-
public actual val ZERO: UtcOffset = UtcOffset(JodaTimeZoneOffset.UTC)
22+
public actual val ZERO: UtcOffset = UtcOffset(jtZoneOffset.UTC)
2623

2724
public actual fun parse(offsetString: String): UtcOffset = try {
28-
JodaTimeZoneOffset.of(offsetString).let(::UtcOffset)
25+
jtZoneOffset.of(offsetString).let(::UtcOffset)
2926
} catch (e: Throwable) {
3027
if (e.isJodaDateTimeException()) throw DateTimeFormatException(e)
3128
throw e
@@ -38,13 +35,11 @@ public actual fun UtcOffset(hours: Int? = null, minutes: Int? = null, seconds: I
3835
try {
3936
when {
4037
hours != null ->
41-
UtcOffset(JodaTimeZoneOffset.ofHoursMinutesSeconds(hours, minutes ?: 0, seconds ?: 0))
42-
38+
UtcOffset(jtZoneOffset.ofHoursMinutesSeconds(hours, minutes ?: 0, seconds ?: 0))
4339
minutes != null ->
44-
UtcOffset(JodaTimeZoneOffset.ofHoursMinutesSeconds(minutes / 60, minutes % 60, seconds ?: 0))
45-
40+
UtcOffset(jtZoneOffset.ofHoursMinutesSeconds(minutes / 60, minutes % 60, seconds ?: 0))
4641
else -> {
47-
UtcOffset(JodaTimeZoneOffset.ofTotalSeconds(seconds ?: 0))
42+
UtcOffset(jtZoneOffset.ofTotalSeconds(seconds ?: 0))
4843
}
4944
}
5045
} catch (e: Throwable) {

0 commit comments

Comments
 (0)