Skip to content

Commit 3e2329e

Browse files
committed
Converting to Boolean and LocalTime
1 parent 64cd9e8 commit 3e2329e

File tree

1 file changed

+8
-0
lines changed
  • core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/impl/api

1 file changed

+8
-0
lines changed

core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/impl/api/convert.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ internal fun createConverter(from: KType, to: KType, options: ParserOptions? = n
206206
Byte::class -> convert<Number> { it.toByte() }
207207
Short::class -> convert<Number> { it.toShort() }
208208
Long::class -> convert<Number> { it.toLong() }
209+
Boolean::class -> convert<Number> { it != 0 }
209210
else -> null
210211
}
211212
Int::class -> when (toClass) {
@@ -215,6 +216,7 @@ internal fun createConverter(from: KType, to: KType, options: ParserOptions? = n
215216
Short::class -> convert<Int> { it.toShort() }
216217
Long::class -> convert<Int> { it.toLong() }
217218
BigDecimal::class -> convert<Int> { it.toBigDecimal() }
219+
Boolean::class -> convert<Int> { it != 0 }
218220
LocalDateTime::class -> convert<Int> { it.toLong().toLocalDateTime(defaultTimeZone) }
219221
LocalDate::class -> convert<Int> { it.toLong().toLocalDate(defaultTimeZone) }
220222
java.time.LocalDateTime::class -> convert<Long> { it.toLocalDateTime(defaultTimeZone).toJavaLocalDateTime() }
@@ -228,6 +230,7 @@ internal fun createConverter(from: KType, to: KType, options: ParserOptions? = n
228230
Long::class -> convert<Double> { it.roundToLong() }
229231
Short::class -> convert<Double> { it.roundToInt().toShort() }
230232
BigDecimal::class -> convert<Double> { it.toBigDecimal() }
233+
Boolean::class -> convert<Double> { it != 0.0 }
231234
else -> null
232235
}
233236
Long::class -> when (toClass) {
@@ -237,6 +240,7 @@ internal fun createConverter(from: KType, to: KType, options: ParserOptions? = n
237240
Short::class -> convert<Long> { it.toShort() }
238241
Int::class -> convert<Long> { it.toInt() }
239242
BigDecimal::class -> convert<Long> { it.toBigDecimal() }
243+
Boolean::class -> convert<Long> { it != 0L }
240244
LocalDateTime::class -> convert<Long> { it.toLocalDateTime(defaultTimeZone) }
241245
LocalDate::class -> convert<Long> { it.toLocalDate(defaultTimeZone) }
242246
Instant::class -> convert<Long> { Instant.fromEpochMilliseconds(it) }
@@ -271,13 +275,15 @@ internal fun createConverter(from: KType, to: KType, options: ParserOptions? = n
271275
Int::class -> convert<Float> { it.roundToInt() }
272276
Short::class -> convert<Float> { it.roundToInt().toShort() }
273277
BigDecimal::class -> convert<Float> { it.toBigDecimal() }
278+
Boolean::class -> convert<Float> { it != 0.0F }
274279
else -> null
275280
}
276281
BigDecimal::class -> when (toClass) {
277282
Double::class -> convert<BigDecimal> { it.toDouble() }
278283
Int::class -> convert<BigDecimal> { it.toInt() }
279284
Float::class -> convert<BigDecimal> { it.toFloat() }
280285
Long::class -> convert<BigDecimal> { it.toLong() }
286+
Boolean::class -> convert<BigDecimal> { it != BigDecimal.ZERO }
281287
else -> null
282288
}
283289
LocalDateTime::class -> when (toClass) {
@@ -286,6 +292,7 @@ internal fun createConverter(from: KType, to: KType, options: ParserOptions? = n
286292
Long::class -> convert<LocalDateTime> { it.toInstant(defaultTimeZone).toEpochMilliseconds() }
287293
java.time.LocalDateTime::class -> convert<LocalDateTime> { it.toJavaLocalDateTime() }
288294
java.time.LocalDate::class -> convert<LocalDateTime> { it.date.toJavaLocalDate() }
295+
java.time.LocalTime::class -> convert<LocalDateTime> { it.toJavaLocalDateTime().toLocalTime() }
289296
else -> null
290297
}
291298
java.time.LocalDateTime::class -> when (toClass) {
@@ -294,6 +301,7 @@ internal fun createConverter(from: KType, to: KType, options: ParserOptions? = n
294301
Instant::class -> convert<java.time.LocalDateTime> { it.toKotlinLocalDateTime().toInstant(defaultTimeZone) }
295302
Long::class -> convert<java.time.LocalDateTime> { it.toKotlinLocalDateTime().toInstant(defaultTimeZone).toEpochMilliseconds() }
296303
java.time.LocalDate::class -> convert<java.time.LocalDateTime> { it.toLocalDate() }
304+
java.time.LocalTime::class -> convert<java.time.LocalDateTime> { it.toLocalTime() }
297305
else -> null
298306
}
299307
LocalDate::class -> when (toClass) {

0 commit comments

Comments
 (0)