can't convert column to toLocalDateTime with format
I miss this function:
df.convert("date_time").toLocalDateTime("yyyy-MM-dd'T'HH:mm:ss'Z'")
Hi! Do you have a sample of code that parses String to LocalDateTime using this format?
val json = """{
"name": "Petr",
"date": "2000-13-21T15:27:49Z"
}"""
val df = DataFrame.readJsonStr(json)
then I try to convert a type of date to LocalDateTime using String API and I can convert with default local but can't with my local:
df.convert("date").toLocalDateTime() // works fine
df.convert("date").toLocalDateTime("yyyy-MM-dd'T'HH:mm:ss'Z'") // missing toLocalDateTime fun
@Jolanrensen please check
This is intentional. The function you're looking for is defined like:
public fun <T, R : String?> Convert<T, R>.toLocalDateTime(
pattern: String? = null,
locale: Locale? = null,
): DataFrame<T> = to { it.convertToLocalDateTime(pattern, locale) }
and thus can only be called on String-typed columns, not Any columns. This means that this does work:
df.convert { "date"<String>() }.toLocalDateTime("yyyy-MM-dd'T'HH:mm:ss'Z'")
// or
df.convert(column<String>("date")).toLocalDateTime("yyyy-MM-dd'T'HH:mm:ss'Z'")
I don't think it's wise to open this up to columns of any type.
Probably close, if won't fix?
@zaleslaw if we all agree :) @koperagen what do you think?
@Jolanrensen
df.convert { "date"<String>() }.toLocalDateTime("yyyy-MM-dd'T'HH:mm:ss'Z'")
Will this also work for <String?>?
@Jolanrensen
df.convert { "date"<String>() }.toLocalDateTime("yyyy-MM-dd'T'HH:mm:ss'Z'")Will this also work for <String?>?
I'd imagine yes, because of:
public fun <T, R : String?> Convert<T, R>.toLocalDateTime(