Skip to content

Commit ca65923

Browse files
committed
added missing LocalTime converters and test
1 parent 7a895e2 commit ca65923

File tree

2 files changed

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

2 files changed

+24
-0
lines changed

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import kotlinx.datetime.toJavaLocalTime
1515
import kotlinx.datetime.toKotlinInstant
1616
import kotlinx.datetime.toKotlinLocalDate
1717
import kotlinx.datetime.toKotlinLocalDateTime
18+
import kotlinx.datetime.toKotlinLocalTime
1819
import kotlinx.datetime.toLocalDateTime
1920
import org.jetbrains.kotlinx.dataframe.AnyCol
2021
import org.jetbrains.kotlinx.dataframe.DataColumn
@@ -350,6 +351,8 @@ internal fun createConverter(from: KType, to: KType, options: ParserOptions? = n
350351

351352
LocalDate::class -> convert<Long> { it.toLocalDate(defaultTimeZone) }
352353

354+
LocalTime::class -> convert<Long> { it.toLocalTime(defaultTimeZone) }
355+
353356
Instant::class -> convert<Long> { Instant.fromEpochMilliseconds(it) }
354357

355358
JavaLocalDateTime::class -> convert<Long> {
@@ -504,6 +507,16 @@ internal fun createConverter(from: KType, to: KType, options: ParserOptions? = n
504507
else -> null
505508
}
506509

510+
LocalTime::class -> when (toClass) {
511+
JavaLocalTime::class -> convert<LocalTime> { it.toJavaLocalTime() }
512+
else -> null
513+
}
514+
515+
JavaLocalTime::class -> when (toClass) {
516+
LocalTime::class -> convert<JavaLocalTime> { it.toKotlinLocalTime() }
517+
else -> null
518+
}
519+
507520
URL::class -> when (toClass) {
508521
IMG::class -> convert<URL> { IMG(it.toString()) }
509522
IFRAME::class -> convert<URL> { IFRAME(it.toString()) }

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,20 @@ import org.jetbrains.kotlinx.dataframe.hasNulls
1616
import org.junit.Test
1717
import kotlin.reflect.typeOf
1818
import kotlin.time.Duration.Companion.hours
19+
import java.time.LocalTime as JavaLocalTime
1920

2021
class ConvertTests {
2122

23+
@Test
24+
fun `convert LocalTime Kotlin to Java and back`() {
25+
val time by columnOf(LocalTime(11, 22, 33))
26+
val converted = time.toDataFrame().convert { time }.to<JavaLocalTime>()
27+
converted[time][0] shouldBe JavaLocalTime.of(11, 22, 33)
28+
29+
val convertedBack = converted.convert(time).to<LocalTime>()
30+
convertedBack[time][0] shouldBe time[0]
31+
}
32+
2233
@Test
2334
fun `convert nullable strings to time`() {
2435
val time by columnOf("11?22?33", null)

0 commit comments

Comments
 (0)