@@ -67,16 +67,14 @@ public actual class Instant internal constructor(internal val value: jtInstant)
67
67
Instant (jtClock.systemUTC().instant())
68
68
69
69
public actual fun fromEpochMilliseconds (epochMilliseconds : Long ): Instant = try {
70
- jsTry {
71
- fromEpochSeconds(epochMilliseconds / MILLIS_PER_ONE , epochMilliseconds % MILLIS_PER_ONE * NANOS_PER_MILLI )
72
- }
70
+ fromEpochSeconds(epochMilliseconds / MILLIS_PER_ONE , epochMilliseconds % MILLIS_PER_ONE * NANOS_PER_MILLI )
73
71
} catch (e: Throwable ) {
74
72
if (! e.isJodaDateTimeException()) throw e
75
73
if (epochMilliseconds > 0 ) MAX else MIN
76
74
}
77
75
78
76
public actual fun parse (isoString : String ): Instant = try {
79
- Instant (jsTry { jtOffsetDateTime.parse(fixOffsetRepresentation(isoString)) } .toInstant())
77
+ Instant (jtOffsetDateTime.parse(fixOffsetRepresentation(isoString)).toInstant())
80
78
} catch (e: Throwable ) {
81
79
if (e.isJodaDateTimeParseException()) throw DateTimeFormatException (e)
82
80
throw e
@@ -94,21 +92,19 @@ public actual class Instant internal constructor(internal val value: jtInstant)
94
92
}
95
93
96
94
public actual fun fromEpochSeconds (epochSeconds : Long , nanosecondAdjustment : Long ): Instant = try {
97
- jsTry {
98
95
/* Performing normalization here because otherwise this fails:
99
96
assertEquals((Long.MAX_VALUE % 1_000_000_000).toInt(),
100
97
Instant.fromEpochSeconds(0, Long.MAX_VALUE).nanosecondsOfSecond) */
101
98
val secs = safeAdd(epochSeconds, nanosecondAdjustment.floorDiv(NANOS_PER_ONE .toLong()))
102
99
val nos = nanosecondAdjustment.mod(NANOS_PER_ONE .toLong()).toInt()
103
100
Instant (jtInstant.ofEpochSecond(secs.toDouble(), nos))
104
- }
105
101
} catch (e: Throwable ) {
106
102
if (! e.isJodaDateTimeException() && e !is ArithmeticException ) throw e
107
103
if (epochSeconds > 0 ) MAX else MIN
108
104
}
109
105
110
106
public actual fun fromEpochSeconds (epochSeconds : Long , nanosecondAdjustment : Int ): Instant = try {
111
- jsTry { Instant (jtInstant.ofEpochSecond(epochSeconds.toDouble(), nanosecondAdjustment)) }
107
+ Instant (jtInstant.ofEpochSecond(epochSeconds.toDouble(), nanosecondAdjustment))
112
108
} catch (e: Throwable ) {
113
109
if (! e.isJodaDateTimeException()) throw e
114
110
if (epochSeconds > 0 ) MAX else MIN
@@ -124,18 +120,16 @@ public actual class Instant internal constructor(internal val value: jtInstant)
124
120
125
121
126
122
public actual fun Instant.plus (period : DateTimePeriod , timeZone : TimeZone ): Instant = try {
127
- jsTry {
128
- val thisZdt = this .value.atZone(timeZone.zoneId)
129
- with (period) {
130
- thisZdt
131
- .run { if (totalMonths != 0 ) plusMonths(totalMonths) else this }
132
- .run { if (days != 0 ) plusDays(days) else this }
133
- .run { if (hours != 0 ) plusHours(hours) else this }
134
- .run { if (minutes != 0 ) plusMinutes(minutes) else this }
135
- .run { if (seconds != 0 ) plusSeconds(seconds) else this }
136
- .run { if (nanoseconds != 0 ) plusNanos(nanoseconds.toDouble()) else this }
137
- }.toInstant().let (::Instant )
138
- }
123
+ val thisZdt = this .value.atZone(timeZone.zoneId)
124
+ with (period) {
125
+ 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 }
132
+ }.toInstant().let (::Instant )
139
133
} catch (e: Throwable ) {
140
134
if (e.isJodaDateTimeException()) throw DateTimeArithmeticException (e)
141
135
throw e
@@ -150,40 +144,36 @@ public actual fun Instant.plus(unit: DateTimeUnit, timeZone: TimeZone): Instant
150
144
151
145
public actual fun Instant.plus (value : Long , unit : DateTimeUnit , timeZone : TimeZone ): Instant =
152
146
try {
153
- jsTry {
154
- val thisZdt = this .atZone(timeZone)
155
- when (unit) {
156
- is DateTimeUnit .TimeBased -> {
157
- plus(value, unit).value.checkZone(timeZone)
158
- }
159
-
160
- is DateTimeUnit .DayBased ->
161
- thisZdt.plusDays(value.toDouble() * unit.days).toInstant()
162
-
163
- is DateTimeUnit .MonthBased ->
164
- thisZdt.plusMonths(value.toDouble() * unit.months).toInstant()
165
- }.let (::Instant )
166
- }
147
+ val thisZdt = this .atZone(timeZone)
148
+ when (unit) {
149
+ is DateTimeUnit .TimeBased -> {
150
+ plus(value, unit).value.checkZone(timeZone)
151
+ }
152
+
153
+ is DateTimeUnit .DayBased ->
154
+ thisZdt.plusDays(value.toDouble() * unit.days).toInstant()
155
+
156
+ is DateTimeUnit .MonthBased ->
157
+ thisZdt.plusMonths(value.toDouble() * unit.months).toInstant()
158
+ }.let (::Instant )
167
159
} catch (e: Throwable ) {
168
160
if (e.isJodaDateTimeException()) throw DateTimeArithmeticException (e)
169
161
throw e
170
162
}
171
163
172
164
public actual fun Instant.plus (value : Int , unit : DateTimeUnit , timeZone : TimeZone ): Instant =
173
165
try {
174
- jsTry {
175
- val thisZdt = this .atZone(timeZone)
176
- when (unit) {
177
- is DateTimeUnit .TimeBased ->
178
- plus(value.toLong(), unit).value.checkZone(timeZone)
179
-
180
- is DateTimeUnit .DayBased ->
181
- thisZdt.plusDays(value.toDouble() * unit.days).toInstant()
182
-
183
- is DateTimeUnit .MonthBased ->
184
- thisZdt.plusMonths(value.toDouble() * unit.months).toInstant()
185
- }.let (::Instant )
186
- }
166
+ val thisZdt = this .atZone(timeZone)
167
+ when (unit) {
168
+ is DateTimeUnit .TimeBased ->
169
+ plus(value.toLong(), unit).value.checkZone(timeZone)
170
+
171
+ is DateTimeUnit .DayBased ->
172
+ thisZdt.plusDays(value.toDouble() * unit.days).toInstant()
173
+
174
+ is DateTimeUnit .MonthBased ->
175
+ thisZdt.plusMonths(value.toDouble() * unit.months).toInstant()
176
+ }.let (::Instant )
187
177
} catch (e: Throwable ) {
188
178
if (e.isJodaDateTimeException()) throw DateTimeArithmeticException (e)
189
179
throw e
@@ -197,10 +187,8 @@ public actual fun Instant.minus(value: Int, unit: DateTimeUnit, timeZone: TimeZo
197
187
198
188
public actual fun Instant.plus (value : Long , unit : DateTimeUnit .TimeBased ): Instant =
199
189
try {
200
- jsTry {
201
- multiplyAndDivide(value, unit.nanoseconds, NANOS_PER_ONE .toLong()).let { (d, r) ->
202
- Instant (plusFix(d.toDouble(), r.toInt()))
203
- }
190
+ multiplyAndDivide(value, unit.nanoseconds, NANOS_PER_ONE .toLong()).let { (d, r) ->
191
+ Instant (plusFix(d.toDouble(), r.toInt()))
204
192
}
205
193
} catch (e: Throwable ) {
206
194
if (! e.isJodaDateTimeException()) {
@@ -210,29 +198,25 @@ public actual fun Instant.plus(value: Long, unit: DateTimeUnit.TimeBased): Insta
210
198
}
211
199
212
200
public actual fun Instant.periodUntil (other : Instant , timeZone : TimeZone ): DateTimePeriod = try {
213
- jsTry {
214
- var thisZdt = this .value.atZone(timeZone.zoneId)
215
- val otherZdt = other.value.atZone(timeZone.zoneId)
201
+ var thisZdt = this .value.atZone(timeZone.zoneId)
202
+ val otherZdt = other.value.atZone(timeZone.zoneId)
216
203
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 )
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 )
220
207
221
- buildDateTimePeriod(months.toInt(), days.toInt(), nanoseconds.toLong())
222
- }
208
+ buildDateTimePeriod(months.toInt(), days.toInt(), nanoseconds.toLong())
223
209
} catch (e: Throwable ) {
224
210
if (e.isJodaDateTimeException()) throw DateTimeArithmeticException (e) else throw e
225
211
}
226
212
227
213
public actual fun Instant.until (other : Instant , unit : DateTimeUnit , timeZone : TimeZone ): Long = try {
228
- jsTry {
229
- val thisZdt = this .atZone(timeZone)
230
- val otherZdt = other.atZone(timeZone)
231
- when (unit) {
232
- is DateTimeUnit .TimeBased -> until(other, unit)
233
- is DateTimeUnit .DayBased -> (thisZdt.until(otherZdt, JodaTimeChronoUnit .DAYS ) / unit.days).toLong()
234
- is DateTimeUnit .MonthBased -> (thisZdt.until(otherZdt, JodaTimeChronoUnit .MONTHS ) / unit.months).toLong()
235
- }
214
+ val thisZdt = this .atZone(timeZone)
215
+ val otherZdt = other.atZone(timeZone)
216
+ when (unit) {
217
+ 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()
236
220
}
237
221
} catch (e: ArithmeticException ) {
238
222
if (this < other) Long .MAX_VALUE else Long .MIN_VALUE
0 commit comments