Skip to content

Commit 8f41fbe

Browse files
committed
SEPARATE
1 parent 53a6c47 commit 8f41fbe

12 files changed

+638
-109
lines changed

core/js/src/JsJodaPlatform.kt

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Copyright 2019-2023 JetBrains s.r.o. and contributors.
3+
* Use of this source code is governed by the Apache 2.0 License that can be found in the LICENSE.txt file.
4+
*/
5+
6+
@file:Suppress("NO_EXPLICIT_VISIBILITY_IN_API_MODE")
7+
8+
package kotlinx.datetime.internal
9+
10+
import kotlinx.datetime.internal.JSJoda.*
11+
12+
internal actual fun JodaTimeZoneId.toZoneOffset(): JodaTimeZoneOffset? = this as? JodaTimeZoneOffset
13+
14+
public actual typealias JodaTimeTemporalAccessor = TemporalAccessor
15+
public actual typealias JodaTimeTemporal = Temporal
16+
public actual typealias JodaTimeTemporalUnit = TemporalUnit
17+
public actual typealias JodaTimeTemporalAmount = TemporalAmount
18+
public actual typealias JodaTimeChronoLocalDate = ChronoLocalDate
19+
public actual typealias JodaTimeChronoLocalDateTime = ChronoLocalDateTime
20+
public actual typealias JodaTimeChronoZonedDateTime = ChronoZonedDateTime
21+
public actual typealias JodaTimeChronoUnit = ChronoUnit
22+
public actual typealias JodaTimeClock = Clock
23+
public actual typealias JodaTimeDuration = Duration
24+
public actual typealias JodaTimeInstant = Instant
25+
public actual typealias JodaTimeLocalDate = LocalDate
26+
public actual typealias JodaTimeLocalDateTime = LocalDateTime
27+
public actual typealias JodaTimeLocalTime = LocalTime
28+
public actual typealias JodaTimeOffsetDateTime = OffsetDateTime
29+
public actual typealias JodaTimeZonedDateTime = ZonedDateTime
30+
public actual typealias JodaTimeZoneId = ZoneId
31+
public actual typealias JodaTimeZoneOffset = ZoneOffset
32+
public actual typealias JodaTimeDayOfWeek = DayOfWeek
33+
public actual typealias JodaTimeMonth = Month
34+
public actual typealias JodaTimeZoneRules = ZoneRules

core/jsAndWasmShared/src/DayOfWeek.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
package kotlinx.datetime
77

8-
import kotlinx.datetime.internal.JSJoda.DayOfWeek as jsDayOfWeek
8+
import kotlinx.datetime.internal.JodaTimeDayOfWeek as jsDayOfWeek
99

1010
public actual enum class DayOfWeek {
1111
MONDAY,

core/jsAndWasmShared/src/Instant.kt

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

66
package kotlinx.datetime
77

8-
import kotlinx.datetime.internal.JSJoda.ZonedDateTime
9-
import kotlinx.datetime.internal.JSJoda.Instant as jtInstant
10-
import kotlinx.datetime.internal.JSJoda.OffsetDateTime as jtOffsetDateTime
11-
import kotlinx.datetime.internal.JSJoda.Duration as jtDuration
12-
import kotlinx.datetime.internal.JSJoda.Clock as jtClock
13-
import kotlinx.datetime.internal.JSJoda.ChronoUnit
8+
import kotlinx.datetime.internal.JodaTimeInstant as jtInstant
9+
import kotlinx.datetime.internal.JodaTimeOffsetDateTime as jtOffsetDateTime
10+
import kotlinx.datetime.internal.JodaTimeDuration as jtDuration
11+
import kotlinx.datetime.internal.JodaTimeClock as jtClock
1412
import kotlinx.datetime.internal.safeAdd
1513
import kotlinx.datetime.internal.*
1614
import kotlinx.datetime.serializers.InstantIso8601Serializer
@@ -32,9 +30,9 @@ public actual class Instant internal constructor(internal val value: jtInstant)
3230

3331
public actual operator fun plus(duration: Duration): Instant = duration.toComponents { seconds, nanoseconds ->
3432
return try {
35-
jsTry {
33+
// jsTry {
3634
Instant(plusFix(seconds.toDouble(), nanoseconds))
37-
}
35+
// }
3836
} catch (e: Throwable) {
3937
if (!e.isJodaDateTimeException()) throw e
4038
if (duration.isPositive()) MAX else MIN
@@ -143,7 +141,7 @@ public actual fun Instant.plus(period: DateTimePeriod, timeZone: TimeZone): Inst
143141
throw e
144142
}
145143

146-
private fun Instant.atZone(zone: TimeZone): ZonedDateTime = value.atZone(zone.zoneId)
144+
private fun Instant.atZone(zone: TimeZone): JodaTimeZonedDateTime = value.atZone(zone.zoneId)
147145
private fun jtInstant.checkZone(zone: TimeZone): jtInstant = apply { atZone(zone.zoneId) }
148146

149147
@Deprecated("Use the plus overload with an explicit number of units", ReplaceWith("this.plus(1, unit, timeZone)"))
@@ -216,9 +214,9 @@ public actual fun Instant.periodUntil(other: Instant, timeZone: TimeZone): DateT
216214
var thisZdt = this.value.atZone(timeZone.zoneId)
217215
val otherZdt = other.value.atZone(timeZone.zoneId)
218216

219-
val months = thisZdt.until(otherZdt, ChronoUnit.MONTHS); thisZdt = thisZdt.plusMonths(months)
220-
val days = thisZdt.until(otherZdt, ChronoUnit.DAYS); thisZdt = thisZdt.plusDays(days)
221-
val nanoseconds = thisZdt.until(otherZdt, ChronoUnit.NANOS)
217+
val months = thisZdt.until(otherZdt, JodaTimeChronoUnit.MONTHS); thisZdt = thisZdt.plusMonths(months)
218+
val days = thisZdt.until(otherZdt, JodaTimeChronoUnit.DAYS); thisZdt = thisZdt.plusDays(days)
219+
val nanoseconds = thisZdt.until(otherZdt, JodaTimeChronoUnit.NANOS)
222220

223221
buildDateTimePeriod(months.toInt(), days.toInt(), nanoseconds.toLong())
224222
}
@@ -232,8 +230,8 @@ public actual fun Instant.until(other: Instant, unit: DateTimeUnit, timeZone: Ti
232230
val otherZdt = other.atZone(timeZone)
233231
when (unit) {
234232
is DateTimeUnit.TimeBased -> until(other, unit)
235-
is DateTimeUnit.DayBased -> (thisZdt.until(otherZdt, ChronoUnit.DAYS) / unit.days).toLong()
236-
is DateTimeUnit.MonthBased -> (thisZdt.until(otherZdt, ChronoUnit.MONTHS) / unit.months).toLong()
233+
is DateTimeUnit.DayBased -> (thisZdt.until(otherZdt, JodaTimeChronoUnit.DAYS) / unit.days).toLong()
234+
is DateTimeUnit.MonthBased -> (thisZdt.until(otherZdt, JodaTimeChronoUnit.MONTHS) / unit.months).toLong()
237235
}
238236
}
239237
} catch (e: ArithmeticException) {
+229
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,229 @@
1+
/*
2+
* Copyright 2019-2023 JetBrains s.r.o. and contributors.
3+
* Use of this source code is governed by the Apache 2.0 License that can be found in the LICENSE.txt file.
4+
*/
5+
6+
@file:Suppress("NO_EXPLICIT_VISIBILITY_IN_API_MODE")
7+
8+
package kotlinx.datetime.internal
9+
10+
public expect open class JodaTimeTemporalUnit
11+
public expect open class JodaTimeTemporalAmount
12+
public expect open class JodaTimeChronoLocalDate : JodaTimeTemporal
13+
public expect open class JodaTimeTemporalAccessor
14+
public expect open class JodaTimeChronoLocalDateTime : JodaTimeTemporal {
15+
open fun toInstant(offset: JodaTimeZoneOffset): JodaTimeInstant
16+
}
17+
public expect open class JodaTimeChronoZonedDateTime : JodaTimeTemporal {
18+
fun toInstant(): JodaTimeInstant
19+
}
20+
public expect open class JodaTimeTemporal : JodaTimeTemporalAccessor {
21+
open fun until(endTemporal: JodaTimeTemporal, unit: JodaTimeTemporalUnit): Double
22+
}
23+
24+
25+
public expect open class JodaTimeChronoUnit : JodaTimeTemporalUnit {
26+
override fun equals(other: Any?): Boolean
27+
override fun hashCode(): Int
28+
override fun toString(): String
29+
30+
companion object {
31+
var NANOS: JodaTimeChronoUnit
32+
var DAYS: JodaTimeChronoUnit
33+
var MONTHS: JodaTimeChronoUnit
34+
var YEARS: JodaTimeChronoUnit
35+
}
36+
}
37+
38+
public expect open class JodaTimeClock {
39+
override fun equals(other: Any?): Boolean
40+
override fun hashCode(): Int
41+
override fun toString(): String
42+
fun instant(): JodaTimeInstant
43+
44+
companion object {
45+
fun systemUTC(): JodaTimeClock
46+
}
47+
}
48+
49+
public expect open class JodaTimeDuration : JodaTimeTemporalAmount {
50+
override fun equals(other: Any?): Boolean
51+
override fun hashCode(): Int
52+
override fun toString(): String
53+
fun nano(): Double
54+
fun seconds(): Double
55+
56+
companion object {
57+
fun between(startInclusive: JodaTimeTemporal, endExclusive: JodaTimeTemporal): JodaTimeDuration
58+
}
59+
}
60+
61+
public expect open class JodaTimeInstant : JodaTimeTemporal {
62+
override fun equals(other: Any?): Boolean
63+
override fun hashCode(): Int
64+
override fun toString(): String
65+
fun atZone(zone: JodaTimeZoneId): JodaTimeZonedDateTime
66+
fun compareTo(otherInstant: JodaTimeInstant): Int
67+
fun epochSecond(): Double
68+
fun nano(): Double
69+
70+
companion object {
71+
var MIN: JodaTimeInstant
72+
var MAX: JodaTimeInstant
73+
fun ofEpochSecond(epochSecond: Double, nanoAdjustment: Int): JodaTimeInstant
74+
}
75+
}
76+
77+
public expect open class JodaTimeLocalDate : JodaTimeChronoLocalDate {
78+
override fun equals(other: Any?): Boolean
79+
override fun hashCode(): Int
80+
override fun toString(): String
81+
fun atStartOfDay(zone: JodaTimeZoneId): JodaTimeZonedDateTime
82+
fun compareTo(other: JodaTimeLocalDate): Int
83+
fun dayOfMonth(): Int
84+
fun dayOfWeek(): JodaTimeDayOfWeek
85+
fun dayOfYear(): Int
86+
fun month(): JodaTimeMonth
87+
fun monthValue(): Int
88+
fun plusDays(daysToAdd: Int): JodaTimeLocalDate
89+
fun plusMonths(monthsToAdd: Int): JodaTimeLocalDate
90+
fun toEpochDay(): Double
91+
fun year(): Int
92+
93+
companion object {
94+
var MIN: JodaTimeLocalDate
95+
var MAX: JodaTimeLocalDate
96+
fun of(year: Int, month: Int, dayOfMonth: Int): JodaTimeLocalDate
97+
fun ofEpochDay(epochDay: Int): JodaTimeLocalDate
98+
fun parse(text: String): JodaTimeLocalDate
99+
}
100+
}
101+
102+
public expect open class JodaTimeLocalDateTime : JodaTimeChronoLocalDateTime {
103+
override fun equals(other: Any?): Boolean
104+
override fun hashCode(): Int
105+
override fun toString(): String
106+
fun atZone(zone: JodaTimeZoneId): JodaTimeZonedDateTime
107+
fun compareTo(other: JodaTimeLocalDateTime): Int
108+
fun dayOfMonth(): Int
109+
fun dayOfWeek(): JodaTimeDayOfWeek
110+
fun dayOfYear(): Int
111+
fun hour(): Int
112+
fun minute(): Int
113+
fun month(): JodaTimeMonth
114+
fun monthValue(): Int
115+
fun nano(): Double
116+
fun second(): Int
117+
fun toLocalDate(): JodaTimeLocalDate
118+
fun toLocalTime(): JodaTimeLocalTime
119+
fun year(): Int
120+
121+
companion object {
122+
var MIN: JodaTimeLocalDateTime
123+
var MAX: JodaTimeLocalDateTime
124+
fun of(date: JodaTimeLocalDate, time: JodaTimeLocalTime): JodaTimeLocalDateTime
125+
fun of(year: Int, month: Int, dayOfMonth: Int, hour: Int, minute: Int, second: Int, nanoSecond: Int): JodaTimeLocalDateTime
126+
fun ofInstant(instant: JodaTimeInstant, zoneId: JodaTimeZoneId): JodaTimeLocalDateTime
127+
fun parse(text: String): JodaTimeLocalDateTime
128+
}
129+
}
130+
131+
public expect open class JodaTimeLocalTime : JodaTimeTemporal {
132+
fun compareTo(other: JodaTimeLocalTime): Int
133+
override fun equals(other: Any?): Boolean
134+
override fun hashCode(): Int
135+
override fun toString(): String
136+
fun hour(): Int
137+
fun minute(): Int
138+
fun nano(): Double
139+
fun second(): Int
140+
fun toNanoOfDay(): Double
141+
fun toSecondOfDay(): Int
142+
143+
companion object {
144+
var MIN: JodaTimeLocalTime
145+
var MAX: JodaTimeLocalTime
146+
fun of(hour: Int, minute: Int, second: Int, nanoOfSecond: Int): JodaTimeLocalTime
147+
fun ofNanoOfDay(nanoOfDay: Double): JodaTimeLocalTime
148+
fun ofSecondOfDay(secondOfDay: Int, nanoOfSecond: Int): JodaTimeLocalTime
149+
fun parse(text: String): JodaTimeLocalTime
150+
}
151+
}
152+
153+
public expect open class JodaTimeOffsetDateTime : JodaTimeTemporal {
154+
override fun equals(other: Any?): Boolean
155+
override fun hashCode(): Int
156+
override fun toString(): String
157+
fun toInstant(): JodaTimeInstant
158+
159+
companion object {
160+
fun ofInstant(instant: JodaTimeInstant, zone: JodaTimeZoneId): JodaTimeOffsetDateTime
161+
fun parse(text: String): JodaTimeOffsetDateTime
162+
}
163+
}
164+
165+
public expect open class JodaTimeZonedDateTime : JodaTimeChronoZonedDateTime {
166+
override fun equals(other: Any?): Boolean
167+
override fun hashCode(): Int
168+
override fun toString(): String
169+
fun plusDays(days: Int): JodaTimeZonedDateTime
170+
fun plusDays(days: Double): JodaTimeZonedDateTime
171+
fun plusHours(hours: Int): JodaTimeZonedDateTime
172+
fun plusMinutes(minutes: Int): JodaTimeZonedDateTime
173+
fun plusMonths(months: Int): JodaTimeZonedDateTime
174+
fun plusMonths(months: Double): JodaTimeZonedDateTime
175+
fun plusNanos(nanos: Double): JodaTimeZonedDateTime
176+
fun plusSeconds(seconds: Int): JodaTimeZonedDateTime
177+
}
178+
179+
internal expect fun JodaTimeZoneId.toZoneOffset(): JodaTimeZoneOffset?
180+
181+
public expect open class JodaTimeZoneId {
182+
override fun equals(other: Any?): Boolean
183+
override fun hashCode(): Int
184+
override fun toString(): String
185+
fun id(): String
186+
fun normalized(): JodaTimeZoneId
187+
fun rules(): JodaTimeZoneRules
188+
189+
companion object {
190+
fun systemDefault(): JodaTimeZoneId
191+
fun of(zoneId: String): JodaTimeZoneId
192+
}
193+
}
194+
195+
public expect open class JodaTimeZoneOffset : JodaTimeZoneId {
196+
override fun equals(other: Any?): Boolean
197+
override fun hashCode(): Int
198+
override fun toString(): String
199+
fun totalSeconds(): Int
200+
201+
companion object {
202+
var UTC: JodaTimeZoneOffset
203+
fun of(offsetId: String): JodaTimeZoneOffset
204+
fun ofHoursMinutesSeconds(hours: Int, minutes: Int, seconds: Int): JodaTimeZoneOffset
205+
fun ofTotalSeconds(totalSeconds: Int): JodaTimeZoneOffset
206+
}
207+
}
208+
209+
public expect open class JodaTimeDayOfWeek {
210+
override fun equals(other: Any?): Boolean
211+
override fun hashCode(): Int
212+
override fun toString(): String
213+
fun value(): Int
214+
}
215+
216+
public expect open class JodaTimeMonth {
217+
override fun equals(other: Any?): Boolean
218+
override fun hashCode(): Int
219+
override fun toString(): String
220+
fun value(): Int
221+
}
222+
223+
public expect open class JodaTimeZoneRules {
224+
override fun equals(other: Any?): Boolean
225+
override fun hashCode(): Int
226+
override fun toString(): String
227+
fun isFixedOffset(): Boolean
228+
fun offsetOfInstant(instant: JodaTimeInstant): JodaTimeZoneOffset
229+
}

0 commit comments

Comments
 (0)