1
1
package org.jetbrains.kotlinx.dataframe.impl.api
2
2
3
- import kotlinx.datetime.Instant
4
3
import kotlinx.datetime.LocalDate
5
4
import kotlinx.datetime.LocalDateTime
6
5
import kotlinx.datetime.LocalTime
7
6
import kotlinx.datetime.TimeZone
8
7
import kotlinx.datetime.atStartOfDayIn
9
8
import kotlinx.datetime.atTime
9
+ import kotlinx.datetime.toDeprecatedInstant
10
10
import kotlinx.datetime.toInstant
11
- import kotlinx.datetime.toJavaInstant
12
11
import kotlinx.datetime.toJavaLocalDate
13
12
import kotlinx.datetime.toJavaLocalDateTime
14
13
import kotlinx.datetime.toJavaLocalTime
15
- import kotlinx.datetime.toKotlinInstant
16
14
import kotlinx.datetime.toKotlinLocalDate
17
15
import kotlinx.datetime.toKotlinLocalDateTime
18
16
import kotlinx.datetime.toKotlinLocalTime
19
17
import kotlinx.datetime.toLocalDateTime
18
+ import kotlinx.datetime.toStdlibInstant
20
19
import org.jetbrains.kotlinx.dataframe.AnyCol
21
20
import org.jetbrains.kotlinx.dataframe.DataColumn
22
21
import org.jetbrains.kotlinx.dataframe.DataFrame
@@ -57,13 +56,17 @@ import kotlin.reflect.full.withNullability
57
56
import kotlin.reflect.jvm.jvmErasure
58
57
import kotlin.reflect.typeOf
59
58
import kotlin.text.trim
59
+ import kotlin.time.Instant
60
+ import kotlin.time.toJavaInstant
61
+ import kotlin.time.toKotlinInstant
60
62
import kotlin.toBigDecimal
61
63
import java.time.Instant as JavaInstant
62
64
import java.time.LocalDate as JavaLocalDate
63
65
import java.time.LocalDateTime as JavaLocalDateTime
64
66
import java.time.LocalTime as JavaLocalTime
65
67
import kotlin.toBigDecimal as toBigDecimalKotlin
66
68
import kotlin.toBigInteger as toBigIntegerKotlin
69
+ import kotlinx.datetime.Instant as DeprecatedInstant
67
70
68
71
@PublishedApi
69
72
internal fun <T , C , R > Convert <T , C >.withRowCellImpl (
@@ -398,6 +401,9 @@ internal fun createConverter(from: KType, to: KType, options: ParserOptions? = n
398
401
399
402
Instant ::class -> convert<Int > { Instant .fromEpochMilliseconds(it.toLong()) }
400
403
404
+ // #1350
405
+ DeprecatedInstant ::class -> convert<Int > { DeprecatedInstant .fromEpochMilliseconds(it.toLong()) }
406
+
401
407
JavaLocalDateTime ::class -> convert<Int > {
402
408
it.toLong().toLocalDateTime(defaultTimeZone).toJavaLocalDateTime()
403
409
}
@@ -436,6 +442,9 @@ internal fun createConverter(from: KType, to: KType, options: ParserOptions? = n
436
442
437
443
Instant ::class -> convert<Byte > { Instant .fromEpochMilliseconds(it.toLong()) }
438
444
445
+ // #1350
446
+ DeprecatedInstant ::class -> convert<Byte > { DeprecatedInstant .fromEpochMilliseconds(it.toLong()) }
447
+
439
448
JavaLocalDateTime ::class -> convert<Byte > {
440
449
it.toLong().toLocalDateTime(defaultTimeZone).toJavaLocalDateTime()
441
450
}
@@ -474,6 +483,9 @@ internal fun createConverter(from: KType, to: KType, options: ParserOptions? = n
474
483
475
484
Instant ::class -> convert<Short > { Instant .fromEpochMilliseconds(it.toLong()) }
476
485
486
+ // #1350
487
+ DeprecatedInstant ::class -> convert<Short > { DeprecatedInstant .fromEpochMilliseconds(it.toLong()) }
488
+
477
489
JavaLocalDateTime ::class -> convert<Short > {
478
490
it.toLong().toLocalDateTime(defaultTimeZone).toJavaLocalDateTime()
479
491
}
@@ -524,6 +536,9 @@ internal fun createConverter(from: KType, to: KType, options: ParserOptions? = n
524
536
525
537
Instant ::class -> convert<Long > { Instant .fromEpochMilliseconds(it) }
526
538
539
+ // #1350
540
+ DeprecatedInstant ::class -> convert<Long > { DeprecatedInstant .fromEpochMilliseconds(it) }
541
+
527
542
JavaLocalDateTime ::class -> convert<Long > {
528
543
it.toLocalDateTime(defaultTimeZone).toJavaLocalDateTime()
529
544
}
@@ -556,6 +571,40 @@ internal fun createConverter(from: KType, to: KType, options: ParserOptions? = n
556
571
557
572
JavaLocalTime ::class -> convert<Instant > { it.toLocalTime(defaultTimeZone).toJavaLocalTime() }
558
573
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
+
559
608
else -> null
560
609
}
561
610
@@ -584,6 +633,11 @@ internal fun createConverter(from: KType, to: KType, options: ParserOptions? = n
584
633
it.toKotlinInstant().toLocalTime(defaultTimeZone).toJavaLocalTime()
585
634
}
586
635
636
+ // #1350
637
+ DeprecatedInstant ::class -> convert<JavaInstant > {
638
+ it.toKotlinInstant().toDeprecatedInstant()
639
+ }
640
+
587
641
else -> null
588
642
}
589
643
@@ -625,13 +679,26 @@ internal fun createConverter(from: KType, to: KType, options: ParserOptions? = n
625
679
626
680
LocalDateTime ::class -> when (toClass) {
627
681
LocalDate ::class -> convert<LocalDateTime > { it.date }
682
+
628
683
LocalTime ::class -> convert<LocalDateTime > { it.time }
684
+
629
685
Instant ::class -> convert<LocalDateTime > { it.toInstant(defaultTimeZone) }
686
+
687
+ // #1350
688
+ DeprecatedInstant ::class -> convert<LocalDateTime > {
689
+ it.toInstant(defaultTimeZone).toDeprecatedInstant()
690
+ }
691
+
630
692
Long ::class -> convert<LocalDateTime > { it.toInstant(defaultTimeZone).toEpochMilliseconds() }
693
+
631
694
JavaLocalDateTime ::class -> convert<LocalDateTime > { it.toJavaLocalDateTime() }
695
+
632
696
JavaLocalDate ::class -> convert<LocalDateTime > { it.date.toJavaLocalDate() }
697
+
633
698
JavaLocalTime ::class -> convert<LocalDateTime > { it.toJavaLocalDateTime().toLocalTime() }
699
+
634
700
JavaInstant ::class -> convert<LocalDateTime > { it.toInstant(defaultTimeZone).toJavaInstant() }
701
+
635
702
else -> null
636
703
}
637
704
@@ -646,6 +713,11 @@ internal fun createConverter(from: KType, to: KType, options: ParserOptions? = n
646
713
it.toKotlinLocalDateTime().toInstant(defaultTimeZone)
647
714
}
648
715
716
+ // #1350
717
+ DeprecatedInstant ::class -> convert<JavaLocalDateTime > {
718
+ it.toKotlinLocalDateTime().toInstant(defaultTimeZone).toDeprecatedInstant()
719
+ }
720
+
649
721
Long ::class -> convert<JavaLocalDateTime > {
650
722
it.toKotlinLocalDateTime().toInstant(defaultTimeZone).toEpochMilliseconds()
651
723
}
@@ -663,11 +735,22 @@ internal fun createConverter(from: KType, to: KType, options: ParserOptions? = n
663
735
664
736
LocalDate ::class -> when (toClass) {
665
737
LocalDateTime ::class -> convert<LocalDate > { it.atTime(0 , 0 ) }
738
+
666
739
Instant ::class -> convert<LocalDate > { it.atStartOfDayIn(defaultTimeZone) }
740
+
741
+ // #1350
742
+ DeprecatedInstant ::class -> convert<LocalDate > {
743
+ it.atStartOfDayIn(defaultTimeZone).toDeprecatedInstant()
744
+ }
745
+
667
746
Long ::class -> convert<LocalDate > { it.atStartOfDayIn(defaultTimeZone).toEpochMilliseconds() }
747
+
668
748
JavaLocalDate ::class -> convert<LocalDate > { it.toJavaLocalDate() }
749
+
669
750
JavaLocalDateTime ::class -> convert<LocalDate > { it.atTime(0 , 0 ).toJavaLocalDateTime() }
751
+
670
752
JavaInstant ::class -> convert<LocalDate > { it.atStartOfDayIn(defaultTimeZone).toJavaInstant() }
753
+
671
754
else -> null
672
755
}
673
756
@@ -680,6 +763,11 @@ internal fun createConverter(from: KType, to: KType, options: ParserOptions? = n
680
763
it.toKotlinLocalDate().atStartOfDayIn(defaultTimeZone)
681
764
}
682
765
766
+ // #1350
767
+ DeprecatedInstant ::class -> convert<JavaLocalDate > {
768
+ it.toKotlinLocalDate().atStartOfDayIn(defaultTimeZone).toDeprecatedInstant()
769
+ }
770
+
683
771
Long ::class -> convert<JavaLocalDate > {
684
772
it.toKotlinLocalDate().atStartOfDayIn(defaultTimeZone).toEpochMilliseconds()
685
773
}
0 commit comments