@@ -3,13 +3,15 @@ package org.jetbrains.kotlinx.dataframe.impl.api
33import kotlinx.datetime.Instant
44import kotlinx.datetime.LocalDate
55import kotlinx.datetime.LocalDateTime
6+ import kotlinx.datetime.LocalTime
67import kotlinx.datetime.TimeZone
78import kotlinx.datetime.atStartOfDayIn
89import kotlinx.datetime.atTime
910import kotlinx.datetime.toInstant
1011import kotlinx.datetime.toJavaInstant
1112import kotlinx.datetime.toJavaLocalDate
1213import kotlinx.datetime.toJavaLocalDateTime
14+ import kotlinx.datetime.toJavaLocalTime
1315import kotlinx.datetime.toKotlinInstant
1416import kotlinx.datetime.toKotlinLocalDate
1517import kotlinx.datetime.toKotlinLocalDateTime
@@ -38,7 +40,6 @@ import org.jetbrains.kotlinx.dataframe.path
3840import org.jetbrains.kotlinx.dataframe.type
3941import java.math.BigDecimal
4042import java.net.URL
41- import java.time.LocalTime
4243import java.util.Locale
4344import kotlin.math.roundToInt
4445import kotlin.math.roundToLong
@@ -49,6 +50,10 @@ import kotlin.reflect.full.memberProperties
4950import kotlin.reflect.full.primaryConstructor
5051import kotlin.reflect.full.withNullability
5152import kotlin.reflect.jvm.jvmErasure
53+ import java.time.Instant as JavaInstant
54+ import java.time.LocalDate as JavaLocalDate
55+ import java.time.LocalDateTime as JavaLocalDateTime
56+ import java.time.LocalTime as JavaLocalTime
5257
5358@PublishedApi
5459internal fun <T , C , R > Convert <T , C >.withRowCellImpl (
@@ -299,13 +304,19 @@ internal fun createConverter(from: KType, to: KType, options: ParserOptions? = n
299304
300305 LocalDate ::class -> convert<Int > { it.toLong().toLocalDate(defaultTimeZone) }
301306
302- java.time.LocalDateTime ::class -> convert<Long > {
303- it.toLocalDateTime(defaultTimeZone).toJavaLocalDateTime()
307+ LocalTime ::class -> convert<Int > { it.toLong().toLocalTime(defaultTimeZone) }
308+
309+ Instant ::class -> convert<Int > { Instant .fromEpochMilliseconds(it.toLong()) }
310+
311+ JavaLocalDateTime ::class -> convert<Int > {
312+ it.toLong().toLocalDateTime(defaultTimeZone).toJavaLocalDateTime()
304313 }
305314
306- java.time. LocalDate ::class -> convert<Long > { it.toLocalDate(defaultTimeZone).toJavaLocalDate() }
315+ JavaLocalDate ::class -> convert<Int > { it.toLong() .toLocalDate(defaultTimeZone).toJavaLocalDate() }
307316
308- LocalTime ::class -> convert<Int > { it.toLong().toLocalTime(defaultTimeZone) }
317+ JavaLocalTime ::class -> convert<Int > { it.toLong().toLocalTime(defaultTimeZone).toJavaLocalTime() }
318+
319+ JavaInstant ::class -> convert<Int > { JavaInstant .ofEpochMilli(it.toLong()) }
309320
310321 else -> null
311322 }
@@ -341,13 +352,15 @@ internal fun createConverter(from: KType, to: KType, options: ParserOptions? = n
341352
342353 Instant ::class -> convert<Long > { Instant .fromEpochMilliseconds(it) }
343354
344- java.time. LocalDateTime ::class -> convert<Long > {
355+ JavaLocalDateTime ::class -> convert<Long > {
345356 it.toLocalDateTime(defaultTimeZone).toJavaLocalDateTime()
346357 }
347358
348- java.time.LocalDate ::class -> convert<Long > { it.toLocalDate(defaultTimeZone).toJavaLocalDate() }
359+ JavaLocalDate ::class -> convert<Long > { it.toLocalDate(defaultTimeZone).toJavaLocalDate() }
360+
361+ JavaLocalTime ::class -> convert<Long > { it.toLocalTime(defaultTimeZone).toJavaLocalTime() }
349362
350- LocalTime ::class -> convert<Long > { it.toLocalTime(defaultTimeZone ) }
363+ JavaInstant ::class -> convert<Long > { JavaInstant .ofEpochMilli(it ) }
351364
352365 else -> null
353366 }
@@ -359,39 +372,45 @@ internal fun createConverter(from: KType, to: KType, options: ParserOptions? = n
359372
360373 LocalDate ::class -> convert<Instant > { it.toLocalDate(defaultTimeZone) }
361374
362- java.time.LocalDateTime ::class -> convert<Instant > {
375+ LocalTime ::class -> convert<Instant > { it.toLocalTime(defaultTimeZone) }
376+
377+ JavaLocalDateTime ::class -> convert<Instant > {
363378 it.toLocalDateTime(defaultTimeZone).toJavaLocalDateTime()
364379 }
365380
366- java.time. LocalDate ::class -> convert<Instant > { it.toLocalDate(defaultTimeZone).toJavaLocalDate() }
381+ JavaLocalDate ::class -> convert<Instant > { it.toLocalDate(defaultTimeZone).toJavaLocalDate() }
367382
368- java.time. Instant ::class -> convert<Instant > { it.toJavaInstant() }
383+ JavaInstant ::class -> convert<Instant > { it.toJavaInstant() }
369384
370- LocalTime ::class -> convert<Instant > { it.toLocalTime(defaultTimeZone) }
385+ JavaLocalTime ::class -> convert<Instant > { it.toLocalTime(defaultTimeZone).toJavaLocalTime( ) }
371386
372387 else -> null
373388 }
374389
375- java.time. Instant ::class -> when (toClass) {
376- Long ::class -> convert< java.time. Instant > { it.toEpochMilli() }
390+ JavaInstant ::class -> when (toClass) {
391+ Long ::class -> convert<JavaInstant > { it.toEpochMilli() }
377392
378- LocalDateTime ::class -> convert< java.time. Instant > {
393+ LocalDateTime ::class -> convert<JavaInstant > {
379394 it.toKotlinInstant().toLocalDateTime(defaultTimeZone)
380395 }
381396
382- LocalDate ::class -> convert< java.time. Instant > { it.toKotlinInstant().toLocalDate(defaultTimeZone) }
397+ LocalDate ::class -> convert<JavaInstant > { it.toKotlinInstant().toLocalDate(defaultTimeZone) }
383398
384- java.time.LocalDateTime ::class -> convert< java.time.Instant > {
399+ LocalTime ::class -> convert<JavaInstant > { it.toKotlinInstant().toLocalTime(defaultTimeZone) }
400+
401+ Instant ::class -> convert<JavaInstant > { it.toKotlinInstant() }
402+
403+ JavaLocalDateTime ::class -> convert<JavaInstant > {
385404 it.toKotlinInstant().toLocalDateTime(defaultTimeZone).toJavaLocalDateTime()
386405 }
387406
388- java.time. LocalDate ::class -> convert< java.time. Instant > {
407+ JavaLocalDate ::class -> convert<JavaInstant > {
389408 it.toKotlinInstant().toLocalDate(defaultTimeZone).toJavaLocalDate()
390409 }
391410
392- Instant ::class -> convert< java.time. Instant > { it.toKotlinInstant() }
393-
394- LocalTime :: class -> convert < java.time. Instant > { it.toKotlinInstant().toLocalTime(defaultTimeZone) }
411+ JavaLocalTime ::class -> convert<JavaInstant > {
412+ it.toKotlinInstant().toLocalTime(defaultTimeZone).toJavaLocalTime()
413+ }
395414
396415 else -> null
397416 }
@@ -417,30 +436,38 @@ internal fun createConverter(from: KType, to: KType, options: ParserOptions? = n
417436
418437 LocalDateTime ::class -> when (toClass) {
419438 LocalDate ::class -> convert<LocalDateTime > { it.date }
439+ LocalTime ::class -> convert<LocalDateTime > { it.time }
420440 Instant ::class -> convert<LocalDateTime > { it.toInstant(defaultTimeZone) }
421441 Long ::class -> convert<LocalDateTime > { it.toInstant(defaultTimeZone).toEpochMilliseconds() }
422- java.time.LocalDateTime ::class -> convert<LocalDateTime > { it.toJavaLocalDateTime() }
423- java.time.LocalDate ::class -> convert<LocalDateTime > { it.date.toJavaLocalDate() }
424- java.time.LocalTime ::class -> convert<LocalDateTime > { it.toJavaLocalDateTime().toLocalTime() }
442+ JavaLocalDateTime ::class -> convert<LocalDateTime > { it.toJavaLocalDateTime() }
443+ JavaLocalDate ::class -> convert<LocalDateTime > { it.date.toJavaLocalDate() }
444+ JavaLocalTime ::class -> convert<LocalDateTime > { it.toJavaLocalDateTime().toLocalTime() }
445+ JavaInstant ::class -> convert<LocalDateTime > { it.toInstant(defaultTimeZone).toJavaInstant() }
425446 else -> null
426447 }
427448
428- java.time.LocalDateTime ::class -> when (toClass) {
429- LocalDate ::class -> convert< java.time.LocalDateTime > { it.toKotlinLocalDateTime().date }
449+ JavaLocalDateTime ::class -> when (toClass) {
450+ LocalDate ::class -> convert<JavaLocalDateTime > { it.toKotlinLocalDateTime().date }
451+
452+ LocalTime ::class -> convert<JavaLocalDateTime > { it.toKotlinLocalDateTime().time }
430453
431- LocalDateTime ::class -> convert< java.time. LocalDateTime > { it.toKotlinLocalDateTime() }
454+ LocalDateTime ::class -> convert<JavaLocalDateTime > { it.toKotlinLocalDateTime() }
432455
433- Instant ::class -> convert< java.time. LocalDateTime > {
456+ Instant ::class -> convert<JavaLocalDateTime > {
434457 it.toKotlinLocalDateTime().toInstant(defaultTimeZone)
435458 }
436459
437- Long ::class -> convert< java.time. LocalDateTime > {
460+ Long ::class -> convert<JavaLocalDateTime > {
438461 it.toKotlinLocalDateTime().toInstant(defaultTimeZone).toEpochMilliseconds()
439462 }
440463
441- java.time. LocalDate ::class -> convert< java.time. LocalDateTime > { it.toLocalDate() }
464+ JavaLocalDate ::class -> convert<JavaLocalDateTime > { it.toLocalDate() }
442465
443- java.time.LocalTime ::class -> convert< java.time.LocalDateTime > { it.toLocalTime() }
466+ JavaLocalTime ::class -> convert<JavaLocalDateTime > { it.toLocalTime() }
467+
468+ JavaInstant ::class -> convert<JavaLocalDateTime > {
469+ it.toKotlinLocalDateTime().toInstant(defaultTimeZone).toJavaInstant()
470+ }
444471
445472 else -> null
446473 }
@@ -449,25 +476,30 @@ internal fun createConverter(from: KType, to: KType, options: ParserOptions? = n
449476 LocalDateTime ::class -> convert<LocalDate > { it.atTime(0 , 0 ) }
450477 Instant ::class -> convert<LocalDate > { it.atStartOfDayIn(defaultTimeZone) }
451478 Long ::class -> convert<LocalDate > { it.atStartOfDayIn(defaultTimeZone).toEpochMilliseconds() }
452- java.time.LocalDate ::class -> convert<LocalDate > { it.toJavaLocalDate() }
453- java.time.LocalDateTime ::class -> convert<LocalDate > { it.atTime(0 , 0 ).toJavaLocalDateTime() }
479+ JavaLocalDate ::class -> convert<LocalDate > { it.toJavaLocalDate() }
480+ JavaLocalDateTime ::class -> convert<LocalDate > { it.atTime(0 , 0 ).toJavaLocalDateTime() }
481+ JavaInstant ::class -> convert<LocalDate > { it.atStartOfDayIn(defaultTimeZone).toJavaInstant() }
454482 else -> null
455483 }
456484
457- java.time. LocalDate ::class -> when (toClass) {
458- LocalDate ::class -> convert< java.time. LocalDate > { it.toKotlinLocalDate() }
485+ JavaLocalDate ::class -> when (toClass) {
486+ LocalDate ::class -> convert<JavaLocalDate > { it.toKotlinLocalDate() }
459487
460- LocalDateTime ::class -> convert< java.time. LocalDate > { it.atTime(0 , 0 ).toKotlinLocalDateTime() }
488+ LocalDateTime ::class -> convert<JavaLocalDate > { it.atTime(0 , 0 ).toKotlinLocalDateTime() }
461489
462- Instant ::class -> convert< java.time. LocalDate > {
490+ Instant ::class -> convert<JavaLocalDate > {
463491 it.toKotlinLocalDate().atStartOfDayIn(defaultTimeZone)
464492 }
465493
466- Long ::class -> convert< java.time. LocalDate > {
494+ Long ::class -> convert<JavaLocalDate > {
467495 it.toKotlinLocalDate().atStartOfDayIn(defaultTimeZone).toEpochMilliseconds()
468496 }
469497
470- java.time.LocalDateTime ::class -> convert< java.time.LocalDate > { it.atStartOfDay() }
498+ JavaLocalDateTime ::class -> convert<JavaLocalDate > { it.atStartOfDay() }
499+
500+ JavaInstant ::class -> convert<JavaLocalDate > {
501+ it.toKotlinLocalDate().atStartOfDayIn(defaultTimeZone).toJavaInstant()
502+ }
471503
472504 else -> null
473505 }
@@ -488,12 +520,10 @@ internal fun Long.toLocalDateTime(zone: TimeZone = defaultTimeZone) =
488520
489521internal fun Long.toLocalDate (zone : TimeZone = defaultTimeZone) = toLocalDateTime(zone).date
490522
491- internal fun Long.toLocalTime (zone : TimeZone = defaultTimeZone) =
492- toLocalDateTime(zone).toJavaLocalDateTime().toLocalTime()
523+ internal fun Long.toLocalTime (zone : TimeZone = defaultTimeZone) = toLocalDateTime(zone).time
493524
494525internal fun Instant.toLocalDate (zone : TimeZone = defaultTimeZone) = toLocalDateTime(zone).date
495526
496- internal fun Instant.toLocalTime (zone : TimeZone = defaultTimeZone) =
497- toLocalDateTime(zone).toJavaLocalDateTime().toLocalTime()
527+ internal fun Instant.toLocalTime (zone : TimeZone = defaultTimeZone) = toLocalDateTime(zone).time
498528
499529internal val defaultTimeZone = TimeZone .currentSystemDefault()
0 commit comments