11package org.jetbrains.kotlinx.dataframe.impl.api
22
3- import kotlinx.datetime.Instant
43import kotlinx.datetime.LocalDate
54import kotlinx.datetime.LocalDateTime
65import kotlinx.datetime.LocalTime
76import kotlinx.datetime.TimeZone
87import kotlinx.datetime.atStartOfDayIn
98import kotlinx.datetime.atTime
9+ import kotlinx.datetime.toDeprecatedInstant
1010import kotlinx.datetime.toInstant
11- import kotlinx.datetime.toJavaInstant
1211import kotlinx.datetime.toJavaLocalDate
1312import kotlinx.datetime.toJavaLocalDateTime
1413import kotlinx.datetime.toJavaLocalTime
15- import kotlinx.datetime.toKotlinInstant
1614import kotlinx.datetime.toKotlinLocalDate
1715import kotlinx.datetime.toKotlinLocalDateTime
1816import kotlinx.datetime.toKotlinLocalTime
1917import kotlinx.datetime.toLocalDateTime
18+ import kotlinx.datetime.toStdlibInstant
2019import org.jetbrains.kotlinx.dataframe.AnyCol
2120import org.jetbrains.kotlinx.dataframe.DataColumn
2221import org.jetbrains.kotlinx.dataframe.DataFrame
@@ -57,13 +56,17 @@ import kotlin.reflect.full.withNullability
5756import kotlin.reflect.jvm.jvmErasure
5857import kotlin.reflect.typeOf
5958import kotlin.text.trim
59+ import kotlin.time.Instant
60+ import kotlin.time.toJavaInstant
61+ import kotlin.time.toKotlinInstant
6062import kotlin.toBigDecimal
6163import java.time.Instant as JavaInstant
6264import java.time.LocalDate as JavaLocalDate
6365import java.time.LocalDateTime as JavaLocalDateTime
6466import java.time.LocalTime as JavaLocalTime
6567import kotlin.toBigDecimal as toBigDecimalKotlin
6668import kotlin.toBigInteger as toBigIntegerKotlin
69+ import kotlinx.datetime.Instant as DeprecatedInstant
6770
6871@PublishedApi
6972internal fun <T , C , R > Convert <T , C >.withRowCellImpl (
@@ -398,6 +401,9 @@ internal fun createConverter(from: KType, to: KType, options: ParserOptions? = n
398401
399402 Instant ::class -> convert<Int > { Instant .fromEpochMilliseconds(it.toLong()) }
400403
404+ // #1350
405+ DeprecatedInstant ::class -> convert<Int > { DeprecatedInstant .fromEpochMilliseconds(it.toLong()) }
406+
401407 JavaLocalDateTime ::class -> convert<Int > {
402408 it.toLong().toLocalDateTime(defaultTimeZone).toJavaLocalDateTime()
403409 }
@@ -436,6 +442,9 @@ internal fun createConverter(from: KType, to: KType, options: ParserOptions? = n
436442
437443 Instant ::class -> convert<Byte > { Instant .fromEpochMilliseconds(it.toLong()) }
438444
445+ // #1350
446+ DeprecatedInstant ::class -> convert<Byte > { DeprecatedInstant .fromEpochMilliseconds(it.toLong()) }
447+
439448 JavaLocalDateTime ::class -> convert<Byte > {
440449 it.toLong().toLocalDateTime(defaultTimeZone).toJavaLocalDateTime()
441450 }
@@ -474,6 +483,9 @@ internal fun createConverter(from: KType, to: KType, options: ParserOptions? = n
474483
475484 Instant ::class -> convert<Short > { Instant .fromEpochMilliseconds(it.toLong()) }
476485
486+ // #1350
487+ DeprecatedInstant ::class -> convert<Short > { DeprecatedInstant .fromEpochMilliseconds(it.toLong()) }
488+
477489 JavaLocalDateTime ::class -> convert<Short > {
478490 it.toLong().toLocalDateTime(defaultTimeZone).toJavaLocalDateTime()
479491 }
@@ -524,6 +536,9 @@ internal fun createConverter(from: KType, to: KType, options: ParserOptions? = n
524536
525537 Instant ::class -> convert<Long > { Instant .fromEpochMilliseconds(it) }
526538
539+ // #1350
540+ DeprecatedInstant ::class -> convert<Long > { DeprecatedInstant .fromEpochMilliseconds(it) }
541+
527542 JavaLocalDateTime ::class -> convert<Long > {
528543 it.toLocalDateTime(defaultTimeZone).toJavaLocalDateTime()
529544 }
@@ -556,6 +571,40 @@ internal fun createConverter(from: KType, to: KType, options: ParserOptions? = n
556571
557572 JavaLocalTime ::class -> convert<Instant > { it.toLocalTime(defaultTimeZone).toJavaLocalTime() }
558573
574+ // #1350
575+ DeprecatedInstant ::class -> convert<Instant > { it.toDeprecatedInstant() }
576+
577+ else -> null
578+ }
579+
580+ // #1350
581+ DeprecatedInstant ::class -> when (toClass) {
582+ Long ::class -> convert<DeprecatedInstant > { it.toStdlibInstant().toEpochMilliseconds() }
583+
584+ LocalDateTime ::class -> convert<DeprecatedInstant > {
585+ it.toStdlibInstant().toLocalDateTime(defaultTimeZone)
586+ }
587+
588+ LocalDate ::class -> convert<DeprecatedInstant > { it.toStdlibInstant().toLocalDate(defaultTimeZone) }
589+
590+ LocalTime ::class -> convert<DeprecatedInstant > { it.toStdlibInstant().toLocalTime(defaultTimeZone) }
591+
592+ JavaLocalDateTime ::class -> convert<DeprecatedInstant > {
593+ it.toStdlibInstant().toLocalDateTime(defaultTimeZone).toJavaLocalDateTime()
594+ }
595+
596+ JavaLocalDate ::class -> convert<DeprecatedInstant > {
597+ it.toStdlibInstant().toLocalDate(defaultTimeZone).toJavaLocalDate()
598+ }
599+
600+ JavaInstant ::class -> convert<DeprecatedInstant > { it.toStdlibInstant().toJavaInstant() }
601+
602+ JavaLocalTime ::class -> convert<DeprecatedInstant > {
603+ it.toStdlibInstant().toLocalTime(defaultTimeZone).toJavaLocalTime()
604+ }
605+
606+ Instant ::class -> convert<DeprecatedInstant > { it.toStdlibInstant() }
607+
559608 else -> null
560609 }
561610
@@ -584,6 +633,11 @@ internal fun createConverter(from: KType, to: KType, options: ParserOptions? = n
584633 it.toKotlinInstant().toLocalTime(defaultTimeZone).toJavaLocalTime()
585634 }
586635
636+ // #1350
637+ DeprecatedInstant ::class -> convert<JavaInstant > {
638+ it.toKotlinInstant().toDeprecatedInstant()
639+ }
640+
587641 else -> null
588642 }
589643
@@ -625,13 +679,26 @@ internal fun createConverter(from: KType, to: KType, options: ParserOptions? = n
625679
626680 LocalDateTime ::class -> when (toClass) {
627681 LocalDate ::class -> convert<LocalDateTime > { it.date }
682+
628683 LocalTime ::class -> convert<LocalDateTime > { it.time }
684+
629685 Instant ::class -> convert<LocalDateTime > { it.toInstant(defaultTimeZone) }
686+
687+ // #1350
688+ DeprecatedInstant ::class -> convert<LocalDateTime > {
689+ it.toInstant(defaultTimeZone).toDeprecatedInstant()
690+ }
691+
630692 Long ::class -> convert<LocalDateTime > { it.toInstant(defaultTimeZone).toEpochMilliseconds() }
693+
631694 JavaLocalDateTime ::class -> convert<LocalDateTime > { it.toJavaLocalDateTime() }
695+
632696 JavaLocalDate ::class -> convert<LocalDateTime > { it.date.toJavaLocalDate() }
697+
633698 JavaLocalTime ::class -> convert<LocalDateTime > { it.toJavaLocalDateTime().toLocalTime() }
699+
634700 JavaInstant ::class -> convert<LocalDateTime > { it.toInstant(defaultTimeZone).toJavaInstant() }
701+
635702 else -> null
636703 }
637704
@@ -646,6 +713,11 @@ internal fun createConverter(from: KType, to: KType, options: ParserOptions? = n
646713 it.toKotlinLocalDateTime().toInstant(defaultTimeZone)
647714 }
648715
716+ // #1350
717+ DeprecatedInstant ::class -> convert<JavaLocalDateTime > {
718+ it.toKotlinLocalDateTime().toInstant(defaultTimeZone).toDeprecatedInstant()
719+ }
720+
649721 Long ::class -> convert<JavaLocalDateTime > {
650722 it.toKotlinLocalDateTime().toInstant(defaultTimeZone).toEpochMilliseconds()
651723 }
@@ -663,11 +735,22 @@ internal fun createConverter(from: KType, to: KType, options: ParserOptions? = n
663735
664736 LocalDate ::class -> when (toClass) {
665737 LocalDateTime ::class -> convert<LocalDate > { it.atTime(0 , 0 ) }
738+
666739 Instant ::class -> convert<LocalDate > { it.atStartOfDayIn(defaultTimeZone) }
740+
741+ // #1350
742+ DeprecatedInstant ::class -> convert<LocalDate > {
743+ it.atStartOfDayIn(defaultTimeZone).toDeprecatedInstant()
744+ }
745+
667746 Long ::class -> convert<LocalDate > { it.atStartOfDayIn(defaultTimeZone).toEpochMilliseconds() }
747+
668748 JavaLocalDate ::class -> convert<LocalDate > { it.toJavaLocalDate() }
749+
669750 JavaLocalDateTime ::class -> convert<LocalDate > { it.atTime(0 , 0 ).toJavaLocalDateTime() }
751+
670752 JavaInstant ::class -> convert<LocalDate > { it.atStartOfDayIn(defaultTimeZone).toJavaInstant() }
753+
671754 else -> null
672755 }
673756
@@ -680,6 +763,11 @@ internal fun createConverter(from: KType, to: KType, options: ParserOptions? = n
680763 it.toKotlinLocalDate().atStartOfDayIn(defaultTimeZone)
681764 }
682765
766+ // #1350
767+ DeprecatedInstant ::class -> convert<JavaLocalDate > {
768+ it.toKotlinLocalDate().atStartOfDayIn(defaultTimeZone).toDeprecatedInstant()
769+ }
770+
683771 Long ::class -> convert<JavaLocalDate > {
684772 it.toKotlinLocalDate().atStartOfDayIn(defaultTimeZone).toEpochMilliseconds()
685773 }
0 commit comments