From d6afe303ce57c6cfbb4befb9ea4380c2b4ddb67f Mon Sep 17 00:00:00 2001 From: Igor Yakovlev Date: Thu, 30 Nov 2023 18:43:28 +0100 Subject: [PATCH] REMOVE REFACTORING --- core/commonJs/src/DayOfWeek.kt | 2 +- core/commonJs/src/Instant.kt | 59 +++--- core/commonJs/src/JSJodaExceptions.kt | 4 +- core/commonJs/src/JsJodaPlatform.kt | 229 --------------------- core/commonJs/src/LocalDate.kt | 22 +-- core/commonJs/src/LocalDateTime.kt | 10 +- core/commonJs/src/LocalTime.kt | 14 +- core/commonJs/src/Month.kt | 2 +- core/commonJs/src/TimeZone.kt | 32 ++- core/commonJs/src/UtcOffset.kt | 12 +- core/js/src/JSJodaExceptions.kt | 4 +- core/js/src/JsJodaPlatform.kt | 34 ---- core/wasmJs/src/JSJodaExceptions.kt | 2 +- core/wasmJs/src/JsJodaPlatform.kt | 273 -------------------------- 14 files changed, 82 insertions(+), 617 deletions(-) delete mode 100644 core/commonJs/src/JsJodaPlatform.kt delete mode 100644 core/js/src/JsJodaPlatform.kt delete mode 100644 core/wasmJs/src/JsJodaPlatform.kt diff --git a/core/commonJs/src/DayOfWeek.kt b/core/commonJs/src/DayOfWeek.kt index 2be61eb7..aff66bbb 100644 --- a/core/commonJs/src/DayOfWeek.kt +++ b/core/commonJs/src/DayOfWeek.kt @@ -5,7 +5,7 @@ package kotlinx.datetime -import kotlinx.datetime.internal.JodaTimeDayOfWeek as jsDayOfWeek +import kotlinx.datetime.internal.JSJoda.DayOfWeek as jsDayOfWeek public actual enum class DayOfWeek { MONDAY, diff --git a/core/commonJs/src/Instant.kt b/core/commonJs/src/Instant.kt index f9d21d18..dfd92e73 100644 --- a/core/commonJs/src/Instant.kt +++ b/core/commonJs/src/Instant.kt @@ -5,11 +5,12 @@ package kotlinx.datetime -import kotlinx.datetime.internal.JodaTimeInstant as jtInstant -import kotlinx.datetime.internal.JodaTimeOffsetDateTime as jtOffsetDateTime -import kotlinx.datetime.internal.JodaTimeDuration as jtDuration -import kotlinx.datetime.internal.JodaTimeClock as jtClock -import kotlinx.datetime.internal.JodaTimeChronoUnit as jtChronoUnit +import kotlinx.datetime.internal.JSJoda.Instant as jtInstant +import kotlinx.datetime.internal.JSJoda.OffsetDateTime as jtOffsetDateTime +import kotlinx.datetime.internal.JSJoda.Duration as jtDuration +import kotlinx.datetime.internal.JSJoda.Clock as jtClock +import kotlinx.datetime.internal.JSJoda.ChronoUnit as jtChronoUnit +import kotlinx.datetime.internal.JSJoda.ZonedDateTime as jtZonedDateTime import kotlinx.datetime.internal.safeAdd import kotlinx.datetime.internal.* import kotlinx.datetime.serializers.InstantIso8601Serializer @@ -41,7 +42,7 @@ public actual class Instant internal constructor(internal val value: jtInstant) internal fun plusFix(seconds: Double, nanos: Int): jtInstant { val newSeconds = value.epochSecond() + seconds val newNanos = value.nano() + nanos - return jtInstant.ofEpochSecond(newSeconds, newNanos.toInt()) + return jsTry { jtInstant.ofEpochSecond(newSeconds, newNanos.toInt()) } } public actual operator fun minus(duration: Duration): Instant = plus(-duration) @@ -54,7 +55,7 @@ public actual class Instant internal constructor(internal val value: jtInstant) public actual override operator fun compareTo(other: Instant): Int = this.value.compareTo(other.value) override fun equals(other: Any?): Boolean = - (this === other) || (other is Instant && this.value == other.value) + (this === other) || (other is Instant && (this.value === other.value || this.value.equals(other.value))) override fun hashCode(): Int = value.hashCode() @@ -73,7 +74,7 @@ public actual class Instant internal constructor(internal val value: jtInstant) } public actual fun parse(isoString: String): Instant = try { - Instant(jtOffsetDateTime.parse(fixOffsetRepresentation(isoString)).toInstant()) + Instant(jsTry { jtOffsetDateTime.parse(fixOffsetRepresentation(isoString)) }.toInstant()) } catch (e: Throwable) { if (e.isJodaDateTimeParseException()) throw DateTimeFormatException(e) throw e @@ -96,21 +97,21 @@ public actual class Instant internal constructor(internal val value: jtInstant) Instant.fromEpochSeconds(0, Long.MAX_VALUE).nanosecondsOfSecond) */ val secs = safeAdd(epochSeconds, nanosecondAdjustment.floorDiv(NANOS_PER_ONE.toLong())) val nos = nanosecondAdjustment.mod(NANOS_PER_ONE.toLong()).toInt() - Instant(jtInstant.ofEpochSecond(secs.toDouble(), nos)) + Instant(jsTry { jtInstant.ofEpochSecond(secs.toDouble(), nos) }) } catch (e: Throwable) { if (!e.isJodaDateTimeException() && e !is ArithmeticException) throw e if (epochSeconds > 0) MAX else MIN } public actual fun fromEpochSeconds(epochSeconds: Long, nanosecondAdjustment: Int): Instant = try { - Instant(jtInstant.ofEpochSecond(epochSeconds.toDouble(), nanosecondAdjustment)) + Instant(jsTry { jtInstant.ofEpochSecond(epochSeconds.toDouble(), nanosecondAdjustment) }) } catch (e: Throwable) { if (!e.isJodaDateTimeException()) throw e if (epochSeconds > 0) MAX else MIN } - public actual val DISTANT_PAST: Instant = Instant(jtInstant.ofEpochSecond(DISTANT_PAST_SECONDS.toDouble(), 999_999_999)) - public actual val DISTANT_FUTURE: Instant = Instant(jtInstant.ofEpochSecond(DISTANT_FUTURE_SECONDS.toDouble(), 0)) + public actual val DISTANT_PAST: Instant = Instant(jsTry { jtInstant.ofEpochSecond(DISTANT_PAST_SECONDS.toDouble(), 999_999_999) }) + public actual val DISTANT_FUTURE: Instant = Instant(jsTry { jtInstant.ofEpochSecond(DISTANT_FUTURE_SECONDS.toDouble(), 0) }) internal actual val MIN: Instant = Instant(jtInstant.MIN) internal actual val MAX: Instant = Instant(jtInstant.MAX) @@ -119,23 +120,23 @@ public actual class Instant internal constructor(internal val value: jtInstant) public actual fun Instant.plus(period: DateTimePeriod, timeZone: TimeZone): Instant = try { - val thisZdt = this.value.atZone(timeZone.zoneId) + val thisZdt = jsTry { this.value.atZone(timeZone.zoneId) } with(period) { thisZdt - .run { if (totalMonths != 0) plusMonths(totalMonths) else this } - .run { if (days != 0) plusDays(days) else this } - .run { if (hours != 0) plusHours(hours) else this } - .run { if (minutes != 0) plusMinutes(minutes) else this } - .run { if (seconds != 0) plusSeconds(seconds) else this } - .run { if (nanoseconds != 0) plusNanos(nanoseconds.toDouble()) else this } + .run { if (totalMonths != 0) jsTry { plusMonths(totalMonths) } else this } + .run { if (days != 0) jsTry { plusDays(days) } else this } + .run { if (hours != 0) jsTry { plusHours(hours) } else this } + .run { if (minutes != 0) jsTry { plusMinutes(minutes) } else this } + .run { if (seconds != 0) jsTry { plusSeconds(seconds) } else this } + .run { if (nanoseconds != 0) jsTry { plusNanos(nanoseconds.toDouble()) } else this } }.toInstant().let(::Instant) } catch (e: Throwable) { if (e.isJodaDateTimeException()) throw DateTimeArithmeticException(e) throw e } -private fun Instant.atZone(zone: TimeZone): JodaTimeZonedDateTime = value.atZone(zone.zoneId) -private fun jtInstant.checkZone(zone: TimeZone): jtInstant = apply { atZone(zone.zoneId) } +private fun Instant.atZone(zone: TimeZone): jtZonedDateTime = jsTry { value.atZone(zone.zoneId) } +private fun jtInstant.checkZone(zone: TimeZone): jtInstant = apply { jsTry { atZone(zone.zoneId) } } @Deprecated("Use the plus overload with an explicit number of units", ReplaceWith("this.plus(1, unit, timeZone)")) public actual fun Instant.plus(unit: DateTimeUnit, timeZone: TimeZone): Instant = @@ -149,9 +150,9 @@ public actual fun Instant.plus(value: Long, unit: DateTimeUnit, timeZone: TimeZo plus(value, unit).value.checkZone(timeZone) } is DateTimeUnit.DayBased -> - thisZdt.plusDays(value.toDouble() * unit.days).toInstant() + jsTry {thisZdt.plusDays(value.toDouble() * unit.days) }.toInstant() is DateTimeUnit.MonthBased -> - thisZdt.plusMonths(value.toDouble() * unit.months).toInstant() + jsTry { thisZdt.plusMonths(value.toDouble() * unit.months) }.toInstant() }.let(::Instant) } catch (e: Throwable) { if (e.isJodaDateTimeException()) throw DateTimeArithmeticException(e) @@ -165,9 +166,9 @@ public actual fun Instant.plus(value: Int, unit: DateTimeUnit, timeZone: TimeZon is DateTimeUnit.TimeBased -> plus(value.toLong(), unit).value.checkZone(timeZone) is DateTimeUnit.DayBased -> - thisZdt.plusDays(value.toDouble() * unit.days).toInstant() + jsTry { thisZdt.plusDays(value.toDouble() * unit.days) }.toInstant() is DateTimeUnit.MonthBased -> - thisZdt.plusMonths(value.toDouble() * unit.months).toInstant() + jsTry { thisZdt.plusMonths(value.toDouble() * unit.months) }.toInstant() }.let(::Instant) } catch (e: Throwable) { if (e.isJodaDateTimeException()) throw DateTimeArithmeticException(e) @@ -193,11 +194,11 @@ public actual fun Instant.plus(value: Long, unit: DateTimeUnit.TimeBased): Insta } public actual fun Instant.periodUntil(other: Instant, timeZone: TimeZone): DateTimePeriod = try { - var thisZdt = this.value.atZone(timeZone.zoneId) - val otherZdt = other.value.atZone(timeZone.zoneId) + var thisZdt = jsTry { this.value.atZone(timeZone.zoneId) } + val otherZdt = jsTry { other.value.atZone(timeZone.zoneId) } - val months = thisZdt.until(otherZdt, jtChronoUnit.MONTHS); thisZdt = thisZdt.plusMonths(months) - val days = thisZdt.until(otherZdt, jtChronoUnit.DAYS); thisZdt = thisZdt.plusDays(days) + val months = thisZdt.until(otherZdt, jtChronoUnit.MONTHS); thisZdt = jsTry { thisZdt.plusMonths(months) } + val days = thisZdt.until(otherZdt, jtChronoUnit.DAYS); thisZdt = jsTry { thisZdt.plusDays(days) } val nanoseconds = thisZdt.until(otherZdt, jtChronoUnit.NANOS) buildDateTimePeriod(months.toInt(), days.toInt(), nanoseconds.toLong()) diff --git a/core/commonJs/src/JSJodaExceptions.kt b/core/commonJs/src/JSJodaExceptions.kt index da414f60..0b854d1a 100644 --- a/core/commonJs/src/JSJodaExceptions.kt +++ b/core/commonJs/src/JSJodaExceptions.kt @@ -9,4 +9,6 @@ internal fun Throwable.isJodaArithmeticException(): Boolean = hasJsExceptionName internal fun Throwable.isJodaDateTimeException(): Boolean = hasJsExceptionName("DateTimeException") internal fun Throwable.isJodaDateTimeParseException(): Boolean = hasJsExceptionName("DateTimeParseException") -internal expect fun Throwable.hasJsExceptionName(name: String): Boolean \ No newline at end of file +internal expect fun Throwable.hasJsExceptionName(name: String): Boolean + +internal expect inline fun jsTry(crossinline body: () -> T): T \ No newline at end of file diff --git a/core/commonJs/src/JsJodaPlatform.kt b/core/commonJs/src/JsJodaPlatform.kt deleted file mode 100644 index a4454165..00000000 --- a/core/commonJs/src/JsJodaPlatform.kt +++ /dev/null @@ -1,229 +0,0 @@ -/* - * Copyright 2019-2023 JetBrains s.r.o. and contributors. - * Use of this source code is governed by the Apache 2.0 License that can be found in the LICENSE.txt file. - */ - -@file:Suppress("NO_EXPLICIT_VISIBILITY_IN_API_MODE") - -package kotlinx.datetime.internal - -public expect open class JodaTimeTemporalUnit -public expect open class JodaTimeTemporalAmount -public expect open class JodaTimeChronoLocalDate : JodaTimeTemporal -public expect open class JodaTimeTemporalAccessor -public expect open class JodaTimeChronoLocalDateTime : JodaTimeTemporal { - open fun toInstant(offset: JodaTimeZoneOffset): JodaTimeInstant -} -public expect open class JodaTimeChronoZonedDateTime : JodaTimeTemporal { - fun toInstant(): JodaTimeInstant -} -public expect open class JodaTimeTemporal : JodaTimeTemporalAccessor { - open fun until(endTemporal: JodaTimeTemporal, unit: JodaTimeTemporalUnit): Double -} - - -public expect open class JodaTimeChronoUnit : JodaTimeTemporalUnit { - override fun equals(other: Any?): Boolean - override fun hashCode(): Int - override fun toString(): String - - companion object { - var NANOS: JodaTimeChronoUnit - var DAYS: JodaTimeChronoUnit - var MONTHS: JodaTimeChronoUnit - var YEARS: JodaTimeChronoUnit - } -} - -public expect open class JodaTimeClock { - override fun equals(other: Any?): Boolean - override fun hashCode(): Int - override fun toString(): String - fun instant(): JodaTimeInstant - - companion object { - fun systemUTC(): JodaTimeClock - } -} - -public expect open class JodaTimeDuration : JodaTimeTemporalAmount { - override fun equals(other: Any?): Boolean - override fun hashCode(): Int - override fun toString(): String - fun nano(): Double - fun seconds(): Double - - companion object { - fun between(startInclusive: JodaTimeTemporal, endExclusive: JodaTimeTemporal): JodaTimeDuration - } -} - -public expect open class JodaTimeInstant : JodaTimeTemporal { - override fun equals(other: Any?): Boolean - override fun hashCode(): Int - override fun toString(): String - fun atZone(zone: JodaTimeZoneId): JodaTimeZonedDateTime - fun compareTo(otherInstant: JodaTimeInstant): Int - fun epochSecond(): Double - fun nano(): Double - - companion object { - var MIN: JodaTimeInstant - var MAX: JodaTimeInstant - fun ofEpochSecond(epochSecond: Double, nanoAdjustment: Int): JodaTimeInstant - } -} - -public expect open class JodaTimeLocalDate : JodaTimeChronoLocalDate { - override fun equals(other: Any?): Boolean - override fun hashCode(): Int - override fun toString(): String - fun atStartOfDay(zone: JodaTimeZoneId): JodaTimeZonedDateTime - fun compareTo(other: JodaTimeLocalDate): Int - fun dayOfMonth(): Int - fun dayOfWeek(): JodaTimeDayOfWeek - fun dayOfYear(): Int - fun month(): JodaTimeMonth - fun monthValue(): Int - fun plusDays(daysToAdd: Int): JodaTimeLocalDate - fun plusMonths(monthsToAdd: Int): JodaTimeLocalDate - fun toEpochDay(): Double - fun year(): Int - - companion object { - var MIN: JodaTimeLocalDate - var MAX: JodaTimeLocalDate - fun of(year: Int, month: Int, dayOfMonth: Int): JodaTimeLocalDate - fun ofEpochDay(epochDay: Int): JodaTimeLocalDate - fun parse(text: String): JodaTimeLocalDate - } -} - -public expect open class JodaTimeLocalDateTime : JodaTimeChronoLocalDateTime { - override fun equals(other: Any?): Boolean - override fun hashCode(): Int - override fun toString(): String - fun atZone(zone: JodaTimeZoneId): JodaTimeZonedDateTime - fun compareTo(other: JodaTimeLocalDateTime): Int - fun dayOfMonth(): Int - fun dayOfWeek(): JodaTimeDayOfWeek - fun dayOfYear(): Int - fun hour(): Int - fun minute(): Int - fun month(): JodaTimeMonth - fun monthValue(): Int - fun nano(): Double - fun second(): Int - fun toLocalDate(): JodaTimeLocalDate - fun toLocalTime(): JodaTimeLocalTime - fun year(): Int - - companion object { - var MIN: JodaTimeLocalDateTime - var MAX: JodaTimeLocalDateTime - fun of(date: JodaTimeLocalDate, time: JodaTimeLocalTime): JodaTimeLocalDateTime - fun of(year: Int, month: Int, dayOfMonth: Int, hour: Int, minute: Int, second: Int, nanoSecond: Int): JodaTimeLocalDateTime - fun ofInstant(instant: JodaTimeInstant, zoneId: JodaTimeZoneId): JodaTimeLocalDateTime - fun parse(text: String): JodaTimeLocalDateTime - } -} - -public expect open class JodaTimeLocalTime : JodaTimeTemporal { - fun compareTo(other: JodaTimeLocalTime): Int - override fun equals(other: Any?): Boolean - override fun hashCode(): Int - override fun toString(): String - fun hour(): Int - fun minute(): Int - fun nano(): Double - fun second(): Int - fun toNanoOfDay(): Double - fun toSecondOfDay(): Int - - companion object { - var MIN: JodaTimeLocalTime - var MAX: JodaTimeLocalTime - fun of(hour: Int, minute: Int, second: Int, nanoOfSecond: Int): JodaTimeLocalTime - fun ofNanoOfDay(nanoOfDay: Double): JodaTimeLocalTime - fun ofSecondOfDay(secondOfDay: Int, nanoOfSecond: Int): JodaTimeLocalTime - fun parse(text: String): JodaTimeLocalTime - } -} - -public expect open class JodaTimeOffsetDateTime : JodaTimeTemporal { - override fun equals(other: Any?): Boolean - override fun hashCode(): Int - override fun toString(): String - fun toInstant(): JodaTimeInstant - - companion object { - fun ofInstant(instant: JodaTimeInstant, zone: JodaTimeZoneId): JodaTimeOffsetDateTime - fun parse(text: String): JodaTimeOffsetDateTime - } -} - -public expect open class JodaTimeZonedDateTime : JodaTimeChronoZonedDateTime { - override fun equals(other: Any?): Boolean - override fun hashCode(): Int - override fun toString(): String - fun plusDays(days: Int): JodaTimeZonedDateTime - fun plusDays(days: Double): JodaTimeZonedDateTime - fun plusHours(hours: Int): JodaTimeZonedDateTime - fun plusMinutes(minutes: Int): JodaTimeZonedDateTime - fun plusMonths(months: Int): JodaTimeZonedDateTime - fun plusMonths(months: Double): JodaTimeZonedDateTime - fun plusNanos(nanos: Double): JodaTimeZonedDateTime - fun plusSeconds(seconds: Int): JodaTimeZonedDateTime -} - -internal expect fun JodaTimeZoneId.toZoneOffset(): JodaTimeZoneOffset? - -public expect open class JodaTimeZoneId { - override fun equals(other: Any?): Boolean - override fun hashCode(): Int - override fun toString(): String - fun id(): String - fun normalized(): JodaTimeZoneId - fun rules(): JodaTimeZoneRules - - companion object { - fun systemDefault(): JodaTimeZoneId - fun of(zoneId: String): JodaTimeZoneId - } -} - -public expect open class JodaTimeZoneOffset : JodaTimeZoneId { - override fun equals(other: Any?): Boolean - override fun hashCode(): Int - override fun toString(): String - fun totalSeconds(): Int - - companion object { - var UTC: JodaTimeZoneOffset - fun of(offsetId: String): JodaTimeZoneOffset - fun ofHoursMinutesSeconds(hours: Int, minutes: Int, seconds: Int): JodaTimeZoneOffset - fun ofTotalSeconds(totalSeconds: Int): JodaTimeZoneOffset - } -} - -public expect open class JodaTimeDayOfWeek { - override fun equals(other: Any?): Boolean - override fun hashCode(): Int - override fun toString(): String - fun value(): Int -} - -public expect open class JodaTimeMonth { - override fun equals(other: Any?): Boolean - override fun hashCode(): Int - override fun toString(): String - fun value(): Int -} - -public expect open class JodaTimeZoneRules { - override fun equals(other: Any?): Boolean - override fun hashCode(): Int - override fun toString(): String - fun isFixedOffset(): Boolean - fun offsetOfInstant(instant: JodaTimeInstant): JodaTimeZoneOffset -} \ No newline at end of file diff --git a/core/commonJs/src/LocalDate.kt b/core/commonJs/src/LocalDate.kt index 17402bf4..30a2dd8f 100644 --- a/core/commonJs/src/LocalDate.kt +++ b/core/commonJs/src/LocalDate.kt @@ -7,14 +7,14 @@ package kotlinx.datetime import kotlinx.datetime.serializers.LocalDateIso8601Serializer import kotlinx.serialization.Serializable -import kotlinx.datetime.internal.JodaTimeLocalDate as jtLocalDate -import kotlinx.datetime.internal.JodaTimeChronoUnit as jtChronoUnit +import kotlinx.datetime.internal.JSJoda.LocalDate as jtLocalDate +import kotlinx.datetime.internal.JSJoda.ChronoUnit as jtChronoUnit @Serializable(with = LocalDateIso8601Serializer::class) public actual class LocalDate internal constructor(internal val value: jtLocalDate) : Comparable { public actual companion object { public actual fun parse(isoString: String): LocalDate = try { - jtLocalDate.parse(isoString).let(::LocalDate) + jsTry { jtLocalDate.parse(isoString) }.let(::LocalDate) } catch (e: Throwable) { if (e.isJodaDateTimeParseException()) throw DateTimeFormatException(e) throw e @@ -24,7 +24,7 @@ public actual class LocalDate internal constructor(internal val value: jtLocalDa internal actual val MAX: LocalDate = LocalDate(jtLocalDate.MAX) public actual fun fromEpochDays(epochDays: Int): LocalDate = try { - LocalDate(jtLocalDate.ofEpochDay(epochDays)) + LocalDate(jsTry { jtLocalDate.ofEpochDay(epochDays) }) } catch (e: Throwable) { if (e.isJodaDateTimeException()) throw IllegalArgumentException(e) throw e @@ -33,7 +33,7 @@ public actual class LocalDate internal constructor(internal val value: jtLocalDa public actual constructor(year: Int, monthNumber: Int, dayOfMonth: Int) : this(try { - jtLocalDate.of(year, monthNumber, dayOfMonth) + jsTry { jtLocalDate.of(year, monthNumber, dayOfMonth) } } catch (e: Throwable) { if (e.isJodaDateTimeException()) throw IllegalArgumentException(e) throw e @@ -49,7 +49,7 @@ public actual class LocalDate internal constructor(internal val value: jtLocalDa public actual val dayOfYear: Int get() = value.dayOfYear() override fun equals(other: Any?): Boolean = - (this === other) || (other is LocalDate && this.value == other.value) + (this === other) || (other is LocalDate && (this.value === other.value || this.value.equals(other.value))) override fun hashCode(): Int = value.hashCode() @@ -69,8 +69,8 @@ public actual fun LocalDate.plus(value: Long, unit: DateTimeUnit.DateBased): Loc private fun LocalDate.plusNumber(value: Number, unit: DateTimeUnit.DateBased): LocalDate = try { when (unit) { - is DateTimeUnit.DayBased -> this.value.plusDays((value.toDouble() * unit.days).toInt()) - is DateTimeUnit.MonthBased -> this.value.plusMonths((value.toDouble() * unit.months).toInt()) + is DateTimeUnit.DayBased -> jsTry { this.value.plusDays((value.toDouble() * unit.days).toInt()) } + is DateTimeUnit.MonthBased -> jsTry { this.value.plusMonths((value.toDouble() * unit.months).toInt()) } }.let(::LocalDate) } catch (e: Throwable) { if (!e.isJodaDateTimeException() && !e.isJodaArithmeticException()) throw e @@ -81,8 +81,8 @@ private fun LocalDate.plusNumber(value: Number, unit: DateTimeUnit.DateBased): L public actual operator fun LocalDate.plus(period: DatePeriod): LocalDate = try { with(period) { return@with value - .run { if (totalMonths != 0) plusMonths(totalMonths) else this } - .run { if (days != 0) plusDays(days) else this } + .run { if (totalMonths != 0) jsTry { plusMonths(totalMonths) } else this } + .run { if (days != 0) jsTry { plusDays(days) } else this } }.let(::LocalDate) } catch (e: Throwable) { @@ -95,7 +95,7 @@ public actual operator fun LocalDate.plus(period: DatePeriod): LocalDate = try { public actual fun LocalDate.periodUntil(other: LocalDate): DatePeriod { var startD = this.value val endD = other.value - val months = startD.until(endD, jtChronoUnit.MONTHS).toInt(); startD = startD.plusMonths(months) + val months = startD.until(endD, jtChronoUnit.MONTHS).toInt(); startD = jsTry { startD.plusMonths(months) } val days = startD.until(endD, jtChronoUnit.DAYS).toInt() return DatePeriod(totalMonths = months, days) diff --git a/core/commonJs/src/LocalDateTime.kt b/core/commonJs/src/LocalDateTime.kt index 9ad47082..ca266a48 100644 --- a/core/commonJs/src/LocalDateTime.kt +++ b/core/commonJs/src/LocalDateTime.kt @@ -6,14 +6,14 @@ package kotlinx.datetime import kotlinx.datetime.serializers.LocalDateTimeIso8601Serializer import kotlinx.serialization.Serializable -import kotlinx.datetime.internal.JodaTimeLocalDateTime as jtLocalDateTime +import kotlinx.datetime.internal.JSJoda.LocalDateTime as jtLocalDateTime @Serializable(with = LocalDateTimeIso8601Serializer::class) public actual class LocalDateTime internal constructor(internal val value: jtLocalDateTime) : Comparable { public actual constructor(year: Int, monthNumber: Int, dayOfMonth: Int, hour: Int, minute: Int, second: Int, nanosecond: Int) : this(try { - jtLocalDateTime.of(year, monthNumber, dayOfMonth, hour, minute, second, nanosecond) + jsTry { jtLocalDateTime.of(year, monthNumber, dayOfMonth, hour, minute, second, nanosecond) } } catch (e: Throwable) { if (e.isJodaDateTimeException()) throw IllegalArgumentException(e) throw e @@ -23,7 +23,7 @@ public actual class LocalDateTime internal constructor(internal val value: jtLoc this(year, month.number, dayOfMonth, hour, minute, second, nanosecond) public actual constructor(date: LocalDate, time: LocalTime) : - this(jtLocalDateTime.of(date.value, time.value)) + this(jsTry { jtLocalDateTime.of(date.value, time.value) }) public actual val year: Int get() = value.year() public actual val monthNumber: Int get() = value.monthValue() @@ -42,7 +42,7 @@ public actual class LocalDateTime internal constructor(internal val value: jtLoc public actual val time: LocalTime get() = LocalTime(value.toLocalTime()) override fun equals(other: Any?): Boolean = - (this === other) || (other is LocalDateTime && this.value == other.value) + (this === other) || (other is LocalDateTime && (this.value === other.value || this.value.equals(other.value))) override fun hashCode(): Int = value.hashCode() @@ -52,7 +52,7 @@ public actual class LocalDateTime internal constructor(internal val value: jtLoc public actual companion object { public actual fun parse(isoString: String): LocalDateTime = try { - jtLocalDateTime.parse(isoString).let(::LocalDateTime) + jsTry { jtLocalDateTime.parse(isoString) }.let(::LocalDateTime) } catch (e: Throwable) { if (e.isJodaDateTimeParseException()) throw DateTimeFormatException(e) throw e diff --git a/core/commonJs/src/LocalTime.kt b/core/commonJs/src/LocalTime.kt index 3c454e11..185d8795 100644 --- a/core/commonJs/src/LocalTime.kt +++ b/core/commonJs/src/LocalTime.kt @@ -7,7 +7,7 @@ package kotlinx.datetime import kotlinx.datetime.internal.* import kotlinx.datetime.serializers.LocalTimeIso8601Serializer import kotlinx.serialization.Serializable -import kotlinx.datetime.internal.JodaTimeLocalTime as jtLocalTime +import kotlinx.datetime.internal.JSJoda.LocalTime as jtLocalTime @Serializable(LocalTimeIso8601Serializer::class) public actual class LocalTime internal constructor(internal val value: jtLocalTime) : @@ -16,7 +16,7 @@ public actual class LocalTime internal constructor(internal val value: jtLocalTi public actual constructor(hour: Int, minute: Int, second: Int, nanosecond: Int) : this( try { - jtLocalTime.of(hour, minute, second, nanosecond) + jsTry { jtLocalTime.of(hour, minute, second, nanosecond) } } catch (e: Throwable) { if (e.isJodaDateTimeException()) throw IllegalArgumentException(e) throw e @@ -32,7 +32,7 @@ public actual class LocalTime internal constructor(internal val value: jtLocalTi public actual fun toNanosecondOfDay(): Long = value.toNanoOfDay().toLong() override fun equals(other: Any?): Boolean = - (this === other) || (other is LocalTime && this.value == other.value) + (this === other) || (other is LocalTime && (this.value === other.value || this.value.equals(other.value))) override fun hashCode(): Int = value.hashCode() @@ -42,27 +42,27 @@ public actual class LocalTime internal constructor(internal val value: jtLocalTi public actual companion object { public actual fun parse(isoString: String): LocalTime = try { - jtLocalTime.parse(isoString).let(::LocalTime) + jsTry { jtLocalTime.parse(isoString) }.let(::LocalTime) } catch (e: Throwable) { if (e.isJodaDateTimeParseException()) throw DateTimeFormatException(e) throw e } public actual fun fromSecondOfDay(secondOfDay: Int): LocalTime = try { - jtLocalTime.ofSecondOfDay(secondOfDay, 0).let(::LocalTime) + jsTry { jtLocalTime.ofSecondOfDay(secondOfDay, 0) }.let(::LocalTime) } catch (e: Throwable) { throw IllegalArgumentException(e) } public actual fun fromMillisecondOfDay(millisecondOfDay: Int): LocalTime = try { - jtLocalTime.ofNanoOfDay(millisecondOfDay * 1_000_000.0).let(::LocalTime) + jsTry { jtLocalTime.ofNanoOfDay(millisecondOfDay * 1_000_000.0) }.let(::LocalTime) } catch (e: Throwable) { throw IllegalArgumentException(e) } public actual fun fromNanosecondOfDay(nanosecondOfDay: Long): LocalTime = try { // number of nanoseconds in a day is much less than `Number.MAX_SAFE_INTEGER`. - jtLocalTime.ofNanoOfDay(nanosecondOfDay.toDouble()).let(::LocalTime) + jsTry { jtLocalTime.ofNanoOfDay(nanosecondOfDay.toDouble()) }.let(::LocalTime) } catch (e: Throwable) { throw IllegalArgumentException(e) } diff --git a/core/commonJs/src/Month.kt b/core/commonJs/src/Month.kt index 77c63da0..ae113dac 100644 --- a/core/commonJs/src/Month.kt +++ b/core/commonJs/src/Month.kt @@ -5,7 +5,7 @@ package kotlinx.datetime -import kotlinx.datetime.internal.JodaTimeMonth as jsMonth +import kotlinx.datetime.internal.JSJoda.Month as jsMonth public actual enum class Month { JANUARY, diff --git a/core/commonJs/src/TimeZone.kt b/core/commonJs/src/TimeZone.kt index 843a94d2..a609c014 100644 --- a/core/commonJs/src/TimeZone.kt +++ b/core/commonJs/src/TimeZone.kt @@ -4,11 +4,9 @@ */ package kotlinx.datetime -import kotlinx.datetime.internal.* -import kotlinx.datetime.internal.JodaTimeZoneId -import kotlinx.datetime.internal.JodaTimeLocalDateTime as jtLocalDateTime -import kotlinx.datetime.internal.JodaTimeZoneId as jtZoneId -import kotlinx.datetime.internal.JodaTimeZoneOffset as jtZoneOffset +import kotlinx.datetime.internal.JSJoda.LocalDateTime as jtLocalDateTime +import kotlinx.datetime.internal.JSJoda.ZoneId as jtZoneId +import kotlinx.datetime.internal.JSJoda.ZoneOffset as jtZoneOffset import kotlinx.datetime.internal.getAvailableZoneIdsSet import kotlinx.datetime.serializers.* import kotlinx.serialization.Serializable @@ -23,7 +21,7 @@ public actual open class TimeZone internal constructor(internal val zoneId: jtZo public actual fun LocalDateTime.toInstant(): Instant = toInstant(this@TimeZone) override fun equals(other: Any?): Boolean = - (this === other) || (other is TimeZone && this.zoneId == other.zoneId) + (this === other) || (other is TimeZone && (this.zoneId === other.zoneId || this.zoneId.equals(other.zoneId))) override fun hashCode(): Int = zoneId.hashCode() @@ -34,21 +32,19 @@ public actual open class TimeZone internal constructor(internal val zoneId: jtZo public actual val UTC: FixedOffsetTimeZone = UtcOffset(jtZoneOffset.UTC).asTimeZone() public actual fun of(zoneId: String): TimeZone = try { - ofZone(jtZoneId.of(zoneId)) + ofZone(jsTry { jtZoneId.of(zoneId) }) } catch (e: Throwable) { if (e.isJodaDateTimeException()) throw IllegalTimeZoneException(e) throw e } - private fun ofZone(zoneId: JodaTimeZoneId): TimeZone { - val zoneOffset = zoneId.toZoneOffset() - return if (zoneOffset != null) { - FixedOffsetTimeZone(UtcOffset(zoneOffset)) - } else if (zoneId.rules().isFixedOffset()) { - FixedOffsetTimeZone(UtcOffset(zoneId.normalized().toZoneOffset()!!), zoneId) - } else { + private fun ofZone(zoneId: jtZoneId): TimeZone = when { + zoneId is jtZoneOffset -> + FixedOffsetTimeZone(UtcOffset(zoneId)) + zoneId.rules().isFixedOffset() -> + FixedOffsetTimeZone(UtcOffset(zoneId.normalized() as jtZoneOffset), zoneId) + else -> TimeZone(zoneId) - } } public actual val availableZoneIds: Set get() = getAvailableZoneIdsSet() @@ -66,14 +62,14 @@ internal constructor(public actual val offset: UtcOffset, zoneId: jtZoneId): Tim public actual fun Instant.toLocalDateTime(timeZone: TimeZone): LocalDateTime = try { - jtLocalDateTime.ofInstant(this.value, timeZone.zoneId).let(::LocalDateTime) + jsTry { jtLocalDateTime.ofInstant(this.value, timeZone.zoneId) }.let(::LocalDateTime) } catch (e: Throwable) { if (e.isJodaDateTimeException()) throw DateTimeArithmeticException(e) throw e } internal actual fun Instant.toLocalDateTime(offset: UtcOffset): LocalDateTime = try { - jtLocalDateTime.ofInstant(this.value, offset.zoneOffset).let(::LocalDateTime) + jsTry { jtLocalDateTime.ofInstant(this.value, offset.zoneOffset) }.let(::LocalDateTime) } catch (e: Throwable) { if (e.isJodaDateTimeException()) throw DateTimeArithmeticException(e) throw e @@ -81,7 +77,7 @@ internal actual fun Instant.toLocalDateTime(offset: UtcOffset): LocalDateTime = // throws DateTimeArithmeticException if the number of milliseconds is too large to represent as a safe int in JS public actual fun TimeZone.offsetAt(instant: Instant): UtcOffset = try { - zoneId.rules().offsetOfInstant(instant.value).let(::UtcOffset) + jsTry { zoneId.rules().offsetOfInstant(instant.value) }.let(::UtcOffset) } catch (e: Throwable) { if (e.isJodaArithmeticException()) throw DateTimeArithmeticException(e) throw e diff --git a/core/commonJs/src/UtcOffset.kt b/core/commonJs/src/UtcOffset.kt index d131e769..89ca752e 100644 --- a/core/commonJs/src/UtcOffset.kt +++ b/core/commonJs/src/UtcOffset.kt @@ -5,7 +5,7 @@ package kotlinx.datetime -import kotlinx.datetime.internal.JodaTimeZoneOffset as jtZoneOffset +import kotlinx.datetime.internal.JSJoda.ZoneOffset as jtZoneOffset import kotlinx.datetime.serializers.UtcOffsetSerializer import kotlinx.serialization.Serializable @@ -14,7 +14,7 @@ public actual class UtcOffset internal constructor(internal val zoneOffset: jtZo public actual val totalSeconds: Int get() = zoneOffset.totalSeconds() override fun hashCode(): Int = zoneOffset.hashCode() - override fun equals(other: Any?): Boolean = other is UtcOffset && this.zoneOffset == other.zoneOffset + override fun equals(other: Any?): Boolean = other is UtcOffset && (this.zoneOffset === other.zoneOffset || this.zoneOffset.equals(other.zoneOffset)) override fun toString(): String = zoneOffset.toString() public actual companion object { @@ -22,7 +22,7 @@ public actual class UtcOffset internal constructor(internal val zoneOffset: jtZo public actual val ZERO: UtcOffset = UtcOffset(jtZoneOffset.UTC) public actual fun parse(offsetString: String): UtcOffset = try { - jtZoneOffset.of(offsetString).let(::UtcOffset) + jsTry { jtZoneOffset.of(offsetString) }.let(::UtcOffset) } catch (e: Throwable) { if (e.isJodaDateTimeException()) throw DateTimeFormatException(e) throw e @@ -35,11 +35,11 @@ public actual fun UtcOffset(hours: Int? = null, minutes: Int? = null, seconds: I try { when { hours != null -> - UtcOffset(jtZoneOffset.ofHoursMinutesSeconds(hours, minutes ?: 0, seconds ?: 0)) + UtcOffset(jsTry { jtZoneOffset.ofHoursMinutesSeconds(hours, minutes ?: 0, seconds ?: 0) }) minutes != null -> - UtcOffset(jtZoneOffset.ofHoursMinutesSeconds(minutes / 60, minutes % 60, seconds ?: 0)) + UtcOffset(jsTry { jtZoneOffset.ofHoursMinutesSeconds(minutes / 60, minutes % 60, seconds ?: 0) }) else -> { - UtcOffset(jtZoneOffset.ofTotalSeconds(seconds ?: 0)) + UtcOffset(jsTry { jtZoneOffset.ofTotalSeconds(seconds ?: 0) }) } } } catch (e: Throwable) { diff --git a/core/js/src/JSJodaExceptions.kt b/core/js/src/JSJodaExceptions.kt index 111b0405..9d0b5347 100644 --- a/core/js/src/JSJodaExceptions.kt +++ b/core/js/src/JSJodaExceptions.kt @@ -6,4 +6,6 @@ package kotlinx.datetime internal actual fun Throwable.hasJsExceptionName(name: String): Boolean = - this.asDynamic().name == name \ No newline at end of file + this.asDynamic().name == name + +internal actual inline fun jsTry(crossinline body: () -> T): T = body() \ No newline at end of file diff --git a/core/js/src/JsJodaPlatform.kt b/core/js/src/JsJodaPlatform.kt deleted file mode 100644 index 92371b7a..00000000 --- a/core/js/src/JsJodaPlatform.kt +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright 2019-2023 JetBrains s.r.o. and contributors. - * Use of this source code is governed by the Apache 2.0 License that can be found in the LICENSE.txt file. - */ - -@file:Suppress("NO_EXPLICIT_VISIBILITY_IN_API_MODE") - -package kotlinx.datetime.internal - -import kotlinx.datetime.internal.JSJoda.* - -internal actual fun JodaTimeZoneId.toZoneOffset(): JodaTimeZoneOffset? = this as? JodaTimeZoneOffset - -public actual typealias JodaTimeTemporalAccessor = TemporalAccessor -public actual typealias JodaTimeTemporal = Temporal -public actual typealias JodaTimeTemporalUnit = TemporalUnit -public actual typealias JodaTimeTemporalAmount = TemporalAmount -public actual typealias JodaTimeChronoLocalDate = ChronoLocalDate -public actual typealias JodaTimeChronoLocalDateTime = ChronoLocalDateTime -public actual typealias JodaTimeChronoZonedDateTime = ChronoZonedDateTime -public actual typealias JodaTimeChronoUnit = ChronoUnit -public actual typealias JodaTimeClock = Clock -public actual typealias JodaTimeDuration = Duration -public actual typealias JodaTimeInstant = Instant -public actual typealias JodaTimeLocalDate = LocalDate -public actual typealias JodaTimeLocalDateTime = LocalDateTime -public actual typealias JodaTimeLocalTime = LocalTime -public actual typealias JodaTimeOffsetDateTime = OffsetDateTime -public actual typealias JodaTimeZonedDateTime = ZonedDateTime -public actual typealias JodaTimeZoneId = ZoneId -public actual typealias JodaTimeZoneOffset = ZoneOffset -public actual typealias JodaTimeDayOfWeek = DayOfWeek -public actual typealias JodaTimeMonth = Month -public actual typealias JodaTimeZoneRules = ZoneRules \ No newline at end of file diff --git a/core/wasmJs/src/JSJodaExceptions.kt b/core/wasmJs/src/JSJodaExceptions.kt index c6d1c413..4f836904 100644 --- a/core/wasmJs/src/JSJodaExceptions.kt +++ b/core/wasmJs/src/JSJodaExceptions.kt @@ -29,7 +29,7 @@ internal class JsException(val jsException: JsAny): Throwable() { get() = getExceptionMessage(jsException) } -internal inline fun jsTry(crossinline body: () -> T): T { +internal actual inline fun jsTry(crossinline body: () -> T): T { var result: T? = null val exception = withCaughtJsException { result = body() diff --git a/core/wasmJs/src/JsJodaPlatform.kt b/core/wasmJs/src/JsJodaPlatform.kt deleted file mode 100644 index ec7b27c2..00000000 --- a/core/wasmJs/src/JsJodaPlatform.kt +++ /dev/null @@ -1,273 +0,0 @@ -/* - * Copyright 2019-2023 JetBrains s.r.o. and contributors. - * Use of this source code is governed by the Apache 2.0 License that can be found in the LICENSE.txt file. - */ - -@file:Suppress("NO_EXPLICIT_VISIBILITY_IN_API_MODE") - -package kotlinx.datetime.internal - -import kotlinx.datetime.internal.JSJoda.* -import kotlinx.datetime.jsTry - -public actual open class JodaTimeTemporalUnit(open val value: TemporalUnit) -public actual open class JodaTimeTemporalAmount -public actual open class JodaTimeChronoLocalDate(override val value: ChronoLocalDate) : JodaTimeTemporal(value) -public actual open class JodaTimeTemporalAccessor(open val value: TemporalAccessor) -public actual open class JodaTimeChronoLocalDateTime(override val value: ChronoLocalDateTime) : JodaTimeTemporal(value) { - actual open fun toInstant(offset: JodaTimeZoneOffset): JodaTimeInstant = JodaTimeInstant(value.toInstant(offset.value)) -} -public actual open class JodaTimeChronoZonedDateTime(override val value: ChronoZonedDateTime) : JodaTimeTemporal(value) { - actual fun toInstant(): JodaTimeInstant = JodaTimeInstant(value.toInstant()) -} -public actual open class JodaTimeTemporal(override val value: Temporal) : JodaTimeTemporalAccessor(value) { - actual open fun until(endTemporal: JodaTimeTemporal, unit: JodaTimeTemporalUnit): Double = - /** - * * Can throw for [JodaTimeZonedDateTime] values if the offsets are different. - * * Can throw for values with local time components if the difference between them is a large number of days - * and the requested time unit is time-based. - * - * The caller must ensure this doesn't happen. - */ - value.until(endTemporal.value, unit.value) -} - -public actual open class JodaTimeChronoUnit(override val value: ChronoUnit) : JodaTimeTemporalUnit(value) { - actual override fun equals(other: Any?): Boolean = other is JodaTimeChronoUnit && value === other.value - actual override fun hashCode(): Int = value.hashCode() - actual override fun toString(): String = value.toString() - - actual companion object { - actual var NANOS: JodaTimeChronoUnit = JodaTimeChronoUnit(ChronoUnit.NANOS) - actual var DAYS: JodaTimeChronoUnit = JodaTimeChronoUnit(ChronoUnit.DAYS) - actual var MONTHS: JodaTimeChronoUnit = JodaTimeChronoUnit(ChronoUnit.MONTHS) - actual var YEARS: JodaTimeChronoUnit = JodaTimeChronoUnit(ChronoUnit.YEARS) - } -} - -public actual open class JodaTimeClock(val value: Clock) { - actual override fun equals(other: Any?): Boolean = other is JodaTimeClock && (value === other.value || value.equals(other.value)) - actual override fun hashCode(): Int = value.hashCode() - actual override fun toString(): String = value.toString() - actual fun instant(): JodaTimeInstant = JodaTimeInstant(value.instant()) - - actual companion object { - actual fun systemUTC(): JodaTimeClock = JodaTimeClock(Clock.systemUTC()) - } -} - -public actual open class JodaTimeDuration(val value: Duration) : JodaTimeTemporalAmount() { - actual override fun equals(other: Any?): Boolean = other is JodaTimeDuration && (value === other.value || value.equals(other.value)) - actual override fun hashCode(): Int = value.hashCode() - actual override fun toString(): String = value.toString() - actual fun nano(): Double = value.nano() - actual fun seconds(): Double = value.seconds() - - actual companion object { - actual fun between(startInclusive: JodaTimeTemporal, endExclusive: JodaTimeTemporal): JodaTimeDuration = - JodaTimeDuration(Duration.between(startInclusive.value, endExclusive.value)) - } -} - -public actual open class JodaTimeInstant(override val value: Instant) : JodaTimeTemporal(value) { - actual override fun equals(other: Any?): Boolean = other is JodaTimeInstant && (value === other.value || value.equals(other.value)) - actual override fun hashCode(): Int = value.hashCode() - actual override fun toString(): String = value.toString() - actual fun atZone(zone: JodaTimeZoneId): JodaTimeZonedDateTime = - JodaTimeZonedDateTime(jsTry { value.atZone(zone.value) }) - actual fun compareTo(otherInstant: JodaTimeInstant): Int = value.compareTo(otherInstant.value) - actual fun epochSecond(): Double = value.epochSecond() - actual fun nano(): Double = value.nano() - - actual companion object { - actual var MIN: JodaTimeInstant = JodaTimeInstant(Instant.MIN) - actual var MAX: JodaTimeInstant = JodaTimeInstant(Instant.MAX) - actual fun ofEpochSecond(epochSecond: Double, nanoAdjustment: Int): JodaTimeInstant = - JodaTimeInstant(jsTry { Instant.ofEpochSecond(epochSecond, nanoAdjustment) }) - } -} - -public actual open class JodaTimeLocalDate(override val value: LocalDate) : JodaTimeChronoLocalDate(value) { - actual override fun equals(other: Any?): Boolean = other is JodaTimeLocalDate && (value === other.value || value.equals(other.value)) - actual override fun hashCode(): Int = value.hashCode() - actual override fun toString(): String = value.toString() - actual fun atStartOfDay(zone: JodaTimeZoneId): JodaTimeZonedDateTime = - JodaTimeZonedDateTime(value.atStartOfDay(zone.value)) - actual fun compareTo(other: JodaTimeLocalDate): Int = value.compareTo(other.value) - actual fun dayOfMonth(): Int = value.dayOfMonth() - actual fun dayOfWeek(): JodaTimeDayOfWeek = JodaTimeDayOfWeek(value.dayOfWeek()) - actual fun dayOfYear(): Int = value.dayOfYear() - actual fun month(): JodaTimeMonth = JodaTimeMonth(value.month()) - actual fun monthValue(): Int = value.monthValue() - actual fun plusDays(daysToAdd: Int): JodaTimeLocalDate = - JodaTimeLocalDate(jsTry { value.plusDays(daysToAdd) }) - actual fun plusMonths(monthsToAdd: Int): JodaTimeLocalDate = - JodaTimeLocalDate(jsTry { value.plusMonths(monthsToAdd) }) - actual fun toEpochDay(): Double = value.toEpochDay() - actual fun year(): Int = value.year() - - actual companion object { - actual var MIN: JodaTimeLocalDate = JodaTimeLocalDate(LocalDate.MIN) - actual var MAX: JodaTimeLocalDate = JodaTimeLocalDate(LocalDate.MAX) - actual fun of(year: Int, month: Int, dayOfMonth: Int): JodaTimeLocalDate = - JodaTimeLocalDate(jsTry { LocalDate.of(year, month, dayOfMonth) }) - actual fun ofEpochDay(epochDay: Int): JodaTimeLocalDate = - JodaTimeLocalDate(jsTry { LocalDate.ofEpochDay(epochDay) }) - actual fun parse(text: String): JodaTimeLocalDate = - JodaTimeLocalDate(jsTry { LocalDate.parse(text) }) - } -} - -public actual open class JodaTimeLocalDateTime(override val value: LocalDateTime) : JodaTimeChronoLocalDateTime(value) { - actual override fun equals(other: Any?): Boolean = other is JodaTimeLocalDateTime && (value === other.value || value.equals(other.value)) - actual override fun hashCode(): Int = value.hashCode() - actual override fun toString(): String = value.toString() - - actual fun atZone(zone: JodaTimeZoneId): JodaTimeZonedDateTime = - JodaTimeZonedDateTime(value.atZone(zone.value)) - actual fun compareTo(other: JodaTimeLocalDateTime): Int = value.compareTo(other.value) - actual fun dayOfMonth(): Int = value.dayOfMonth() - actual fun dayOfWeek(): JodaTimeDayOfWeek = JodaTimeDayOfWeek(value.dayOfWeek()) - actual fun dayOfYear(): Int = value.dayOfYear() - actual fun hour(): Int = value.hour() - actual fun minute(): Int = value.minute() - actual fun month(): JodaTimeMonth = JodaTimeMonth(value.month()) - actual fun monthValue(): Int = value.monthValue() - actual fun nano(): Double = value.nano() - actual fun second(): Int = value.second() - actual fun toLocalDate(): JodaTimeLocalDate = JodaTimeLocalDate(value.toLocalDate()) - actual fun toLocalTime(): JodaTimeLocalTime = JodaTimeLocalTime(value.toLocalTime()) - actual fun year(): Int = value.year() - - actual companion object { - actual var MIN: JodaTimeLocalDateTime = JodaTimeLocalDateTime(LocalDateTime.MIN) - actual var MAX: JodaTimeLocalDateTime = JodaTimeLocalDateTime(LocalDateTime.MAX) - actual fun of(date: JodaTimeLocalDate, time: JodaTimeLocalTime): JodaTimeLocalDateTime = - JodaTimeLocalDateTime(jsTry { LocalDateTime.of(date.value, time.value) }) - actual fun of(year: Int, month: Int, dayOfMonth: Int, hour: Int, minute: Int, second: Int, nanoSecond: Int): JodaTimeLocalDateTime = - JodaTimeLocalDateTime(jsTry { LocalDateTime.of(year, month, dayOfMonth, hour, minute, second, nanoSecond) }) - actual fun ofInstant(instant: JodaTimeInstant, zoneId: JodaTimeZoneId): JodaTimeLocalDateTime = - JodaTimeLocalDateTime(jsTry { LocalDateTime.ofInstant(instant.value, zoneId.value) }) - actual fun parse(text: String): JodaTimeLocalDateTime = - JodaTimeLocalDateTime(jsTry { LocalDateTime.parse(text) }) - } -} - -public actual open class JodaTimeLocalTime(override val value: LocalTime) : JodaTimeTemporal(value) { - actual override fun equals(other: Any?): Boolean = other is JodaTimeLocalTime && (value === other.value || value.equals(other.value)) - actual override fun hashCode(): Int = value.hashCode() - actual override fun toString(): String = value.toString() - actual fun compareTo(other: JodaTimeLocalTime): Int = value.compareTo(other.value) - actual fun hour(): Int = value.hour() - actual fun minute(): Int = value.minute() - actual fun nano(): Double = value.nano() - actual fun second(): Int = value.second() - actual fun toNanoOfDay(): Double = value.toNanoOfDay() - actual fun toSecondOfDay(): Int = value.toSecondOfDay() - - actual companion object { - actual var MIN: JodaTimeLocalTime = JodaTimeLocalTime(LocalTime.MIN) - actual var MAX: JodaTimeLocalTime = JodaTimeLocalTime(LocalTime.MAX) - actual fun of(hour: Int, minute: Int, second: Int, nanoOfSecond: Int): JodaTimeLocalTime = - JodaTimeLocalTime(jsTry { LocalTime.of(hour, minute, second, nanoOfSecond) }) - actual fun ofNanoOfDay(nanoOfDay: Double): JodaTimeLocalTime = - JodaTimeLocalTime(jsTry { LocalTime.ofNanoOfDay(nanoOfDay) }) - actual fun ofSecondOfDay(secondOfDay: Int, nanoOfSecond: Int): JodaTimeLocalTime = - JodaTimeLocalTime(jsTry { LocalTime.ofSecondOfDay(secondOfDay, nanoOfSecond) }) - actual fun parse(text: String): JodaTimeLocalTime = - JodaTimeLocalTime(jsTry { LocalTime.parse(text) }) - } -} - -public actual open class JodaTimeOffsetDateTime(override val value: OffsetDateTime) : JodaTimeTemporal(value) { - actual override fun equals(other: Any?): Boolean = other is JodaTimeOffsetDateTime && (value === other.value || value.equals(other.value)) - actual override fun hashCode(): Int = value.hashCode() - actual override fun toString(): String = value.toString() - actual fun toInstant(): JodaTimeInstant = JodaTimeInstant(value.toInstant()) - - actual companion object { - actual fun ofInstant(instant: JodaTimeInstant, zone: JodaTimeZoneId): JodaTimeOffsetDateTime = - JodaTimeOffsetDateTime(OffsetDateTime.ofInstant(instant.value, zone.value)) - actual fun parse(text: String): JodaTimeOffsetDateTime = - JodaTimeOffsetDateTime(jsTry { OffsetDateTime.parse(text) }) - } -} - -public actual open class JodaTimeZonedDateTime(override val value: ZonedDateTime) : JodaTimeChronoZonedDateTime(value) { - actual override fun equals(other: Any?): Boolean = other is JodaTimeZonedDateTime && (value === other.value || value.equals(other.value)) - actual override fun hashCode(): Int = value.hashCode() - actual override fun toString(): String = value.toString() - actual fun plusDays(days: Int): JodaTimeZonedDateTime = - JodaTimeZonedDateTime(jsTry { value.plusDays(days) }) - actual fun plusDays(days: Double): JodaTimeZonedDateTime = - JodaTimeZonedDateTime(jsTry { value.plusDays(days) }) - actual fun plusHours(hours: Int): JodaTimeZonedDateTime = - JodaTimeZonedDateTime(jsTry { value.plusHours(hours) }) - actual fun plusMinutes(minutes: Int): JodaTimeZonedDateTime = - JodaTimeZonedDateTime(jsTry { value.plusMinutes(minutes) }) - actual fun plusMonths(months: Int): JodaTimeZonedDateTime = - JodaTimeZonedDateTime(jsTry { value.plusMonths(months) }) - actual fun plusMonths(months: Double): JodaTimeZonedDateTime = - JodaTimeZonedDateTime(jsTry { value.plusMonths(months) }) - actual fun plusNanos(nanos: Double): JodaTimeZonedDateTime = - JodaTimeZonedDateTime(jsTry { value.plusNanos(nanos) }) - actual fun plusSeconds(seconds: Int): JodaTimeZonedDateTime = - JodaTimeZonedDateTime(jsTry { value.plusSeconds(seconds) }) -} - -internal actual fun JodaTimeZoneId.toZoneOffset(): JodaTimeZoneOffset? = - (value as? ZoneOffset)?.let(::JodaTimeZoneOffset) - -public actual open class JodaTimeZoneId(open val value: ZoneId) { - actual override fun equals(other: Any?): Boolean = other is JodaTimeZoneId && (value === other.value || value.equals(other.value)) - actual override fun hashCode(): Int = value.hashCode() - actual override fun toString(): String = value.toString() - actual fun id(): String = value.id() - actual fun normalized(): JodaTimeZoneId = JodaTimeZoneId(value.normalized()) - actual fun rules(): JodaTimeZoneRules = JodaTimeZoneRules(value.rules()) - - actual companion object { - actual fun systemDefault(): JodaTimeZoneId = JodaTimeZoneId(ZoneId.systemDefault()) - actual fun of(zoneId: String): JodaTimeZoneId = JodaTimeZoneId(jsTry { ZoneId.of(zoneId) }) - } -} - -public actual open class JodaTimeZoneOffset(override val value: ZoneOffset) : JodaTimeZoneId(value) { - actual override fun equals(other: Any?): Boolean = other is JodaTimeZoneOffset && (value === other.value || value.equals(other.value)) - actual override fun hashCode(): Int = value.hashCode() - actual override fun toString(): String = value.toString() - actual fun totalSeconds(): Int = value.totalSeconds() - - actual companion object { - actual var UTC: JodaTimeZoneOffset = JodaTimeZoneOffset(ZoneOffset.UTC) - actual fun of(offsetId: String): JodaTimeZoneOffset = - JodaTimeZoneOffset(jsTry { ZoneOffset.of(offsetId) }) - actual fun ofHoursMinutesSeconds(hours: Int, minutes: Int, seconds: Int): JodaTimeZoneOffset = - JodaTimeZoneOffset(jsTry { ZoneOffset.ofHoursMinutesSeconds(hours, minutes, seconds) }) - actual fun ofTotalSeconds(totalSeconds: Int): JodaTimeZoneOffset = - JodaTimeZoneOffset(jsTry { ZoneOffset.ofTotalSeconds(totalSeconds) }) - } -} - -public actual open class JodaTimeDayOfWeek(private val value: DayOfWeek) { - actual override fun equals(other: Any?): Boolean = other is JodaTimeDayOfWeek && (value === other.value || value.equals(other.value)) - actual override fun hashCode(): Int = value.hashCode() - actual override fun toString(): String = value.toString() - actual fun value(): Int = value.value() -} - -public actual open class JodaTimeMonth(private val value: Month) { - actual override fun equals(other: Any?): Boolean = other is JodaTimeMonth && (value === other.value || value.equals(other.value)) - actual override fun hashCode(): Int = value.hashCode() - actual override fun toString(): String = value.toString() - actual fun value(): Int = value.value() -} - -public actual open class JodaTimeZoneRules(private val value: ZoneRules) { - actual override fun equals(other: Any?): Boolean = other is JodaTimeZoneRules && value === other.value - actual override fun hashCode(): Int = value.hashCode() - actual override fun toString(): String = value.toString() - actual fun isFixedOffset(): Boolean = value.isFixedOffset() - actual fun offsetOfInstant(instant: JodaTimeInstant): JodaTimeZoneOffset = - JodaTimeZoneOffset(jsTry { value.offsetOfInstant(instant.value) }) -}