Skip to content

Commit c76386c

Browse files
committed
Add automatic converters from time-related types.
1 parent 122f2dd commit c76386c

File tree

1 file changed

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

1 file changed

+11
-0
lines changed

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import kotlinx.datetime.Instant
44
import kotlinx.datetime.LocalDate
55
import kotlinx.datetime.LocalDateTime
66
import kotlinx.datetime.TimeZone
7+
import kotlinx.datetime.atStartOfDayIn
8+
import kotlinx.datetime.atTime
79
import kotlinx.datetime.toInstant
810
import kotlinx.datetime.toJavaLocalDate
911
import kotlinx.datetime.toJavaLocalDateTime
@@ -217,16 +219,25 @@ internal fun createConverter(from: KType, to: KType, options: ParserOptions? = n
217219
java.time.LocalDateTime::class -> when (toClass) {
218220
LocalDate::class -> convert<java.time.LocalDateTime> { it.toKotlinLocalDateTime().date }
219221
LocalDateTime::class -> convert<java.time.LocalDateTime> { it.toKotlinLocalDateTime() }
222+
Instant::class -> convert<java.time.LocalDateTime> { it.toKotlinLocalDateTime().toInstant(defaultTimeZone) }
220223
Long::class -> convert<java.time.LocalDateTime> { it.toKotlinLocalDateTime().toInstant(defaultTimeZone).toEpochMilliseconds() }
221224
java.time.LocalDate::class -> convert<java.time.LocalDateTime> { it.toLocalDate() }
222225
else -> null
223226
}
224227
LocalDate::class -> when (toClass) {
228+
LocalDateTime::class -> convert<LocalDate> { it.atTime(0, 0) }
229+
Instant::class -> convert<LocalDate> { it.atStartOfDayIn(defaultTimeZone) }
230+
Long::class -> convert<LocalDate> { it.atStartOfDayIn(defaultTimeZone).toEpochMilliseconds() }
225231
java.time.LocalDate::class -> convert<LocalDate> { it.toJavaLocalDate() }
232+
java.time.LocalDateTime::class -> convert<LocalDate> { it.atTime(0, 0).toJavaLocalDateTime() }
226233
else -> null
227234
}
228235
java.time.LocalDate::class -> when (toClass) {
229236
LocalDate::class -> convert<java.time.LocalDate> { it.toKotlinLocalDate() }
237+
LocalDateTime::class -> convert<java.time.LocalDate> { it.atTime(0, 0).toKotlinLocalDateTime() }
238+
Instant::class -> convert<java.time.LocalDate> { it.toKotlinLocalDate().atStartOfDayIn(defaultTimeZone) }
239+
Long::class -> convert<java.time.LocalDate> { it.toKotlinLocalDate().atStartOfDayIn(defaultTimeZone).toEpochMilliseconds() }
240+
java.time.LocalDateTime::class -> convert<java.time.LocalDate> { it.atStartOfDay() }
230241
else -> null
231242
}
232243
URL::class -> when (toClass) {

0 commit comments

Comments
 (0)