@@ -78,8 +78,15 @@ import kotlin.reflect.KProperty
7878import kotlin.reflect.KType
7979import kotlin.reflect.full.isSubtypeOf
8080import kotlin.reflect.typeOf
81+ import kotlin.time.Duration
8182import kotlin.time.Instant as StdlibInstant
8283import kotlinx.datetime.Instant as DeprecatedInstant
84+ import java.time.Instant as JavaInstant
85+ import java.time.Duration as JavaDuration
86+ import java.time.LocalDate as JavaLocalDate
87+ import java.time.LocalTime as JavaLocalTime
88+ import java.time.LocalDateTime as JavaLocalDateTime
89+
8390
8491/* *
8592 * See also [parse] — a specialized form of the [convert] operation that parses [String] columns
@@ -2917,6 +2924,132 @@ public fun <T> Convert<T, *>.toDateTimeComponents(): DataFrame<T> = asColumn { i
29172924
29182925// endregion
29192926
2927+ // region toDuration
2928+
2929+ /* *
2930+ * Converts values in this [String] column to [Duration].
2931+ *
2932+ * Parses each string using [Duration.parse].
2933+ * Fails with an exception if a value cannot be parsed.
2934+ *
2935+ * @return A new [DataColumn] with the [Duration] values.
2936+ */
2937+ @JvmName(" convertToDurationFromString" )
2938+ public fun DataColumn<String>.convertToDuration (): DataColumn <Duration > = convertTo()
2939+
2940+ /* *
2941+ * Converts values in this [String] column to [Duration]. Preserves null values.
2942+ *
2943+ * Parses each string using [Duration.parse].
2944+ * Fails with an exception if a value cannot be parsed.
2945+ *
2946+ * @return A new [DataColumn] with the [Duration] nullable values.
2947+ */
2948+ @JvmName(" convertToDurationFromStringNullable" )
2949+ public fun DataColumn<String?>.convertToDuration (): DataColumn <Duration ?> = convertTo()
2950+
2951+ /* *
2952+ * Converts values in this [JavaDuration] column to [Duration].
2953+ *
2954+ * @return A new [DataColumn] with the [Duration] values.
2955+ */
2956+ @JvmName(" convertToDurationFromJavaDuration" )
2957+ public fun DataColumn<JavaDuration>.convertToDuration (): DataColumn <Duration > = convertTo()
2958+
2959+ /* *
2960+ * Converts values in this [JavaDuration] column to [Duration]. Preserves null values.
2961+ *
2962+ * @return A new [DataColumn] with the [Duration] nullable values.
2963+ */
2964+ @JvmName(" convertToDurationFromJavaDurationNullable" )
2965+ public fun DataColumn<JavaDuration?>.convertToDuration (): DataColumn <Duration ?> = convertTo()
2966+
2967+ /* *
2968+ * Converts values in the [String] columns previously selected with [convert] to [Duration],
2969+ * preserving their original names and positions within the [DataFrame].
2970+ * Preserves null values.
2971+ *
2972+ * Parses each string using [Duration.parse].
2973+ * Fails with an exception if a value cannot be parsed.
2974+ *
2975+ * For more information: {@include [DocumentationUrls.Convert]}
2976+ *
2977+ * ### Examples:
2978+ * ```kotlin
2979+ * df.convert { duration }.toDuration()
2980+ * ```
2981+ *
2982+ * @return A new [DataFrame] with the values converted to [Duration].
2983+ */
2984+ @JvmName(" toDurationFromStringNullable" )
2985+ @Refine
2986+ @Converter(Duration ::class , nullable = true )
2987+ @Interpretable(" ToSpecificType" )
2988+ public fun <T > Convert <T , String ?>.toDuration (): DataFrame <T > = asColumn { it.convertToDuration() }
2989+
2990+ /* *
2991+ * Converts values in the [String] columns previously selected with [convert] to [Duration],
2992+ * preserving their original names and positions within the [DataFrame].
2993+ *
2994+ * Parses each string using [Duration.parse].
2995+ * Fails with an exception if a value cannot be parsed.
2996+ *
2997+ * For more information: {@include [DocumentationUrls.Convert]}
2998+ *
2999+ * ### Examples:
3000+ * ```kotlin
3001+ * df.convert { duration }.toDuration()
3002+ * ```
3003+ *
3004+ * @return A new [DataFrame] with the values converted to [Duration].
3005+ */
3006+ @JvmName(" toDurationFromString" )
3007+ @Refine
3008+ @Converter(Duration ::class , nullable = false )
3009+ @Interpretable(" ToSpecificType" )
3010+ public fun <T > Convert <T , String >.toDuration (): DataFrame <T > = asColumn { it.convertToDuration() }
3011+
3012+ /* *
3013+ * Converts values in the [JavaDuration] columns previously selected with [convert] to [Duration],
3014+ * preserving their original names and positions within the [DataFrame].
3015+ * Preserves null values.
3016+ *
3017+ * For more information: {@include [DocumentationUrls.Convert]}
3018+ *
3019+ * ### Examples:
3020+ * ```kotlin
3021+ * df.convert { duration }.toDuration()
3022+ * ```
3023+ *
3024+ * @return A new [DataFrame] with the values converted to [Duration].
3025+ */
3026+ @JvmName(" toDurationFromJavaDurationNullable" )
3027+ @Refine
3028+ @Converter(Duration ::class , nullable = true )
3029+ @Interpretable(" ToSpecificType" )
3030+ public fun <T > Convert <T , JavaDuration ?>.toDuration (): DataFrame <T > = asColumn { it.convertToDuration() }
3031+
3032+ /* *
3033+ * Converts values in the [JavaDuration] columns previously selected with [convert] to [Duration],
3034+ * preserving their original names and positions within the [DataFrame].
3035+ *
3036+ * For more information: {@include [DocumentationUrls.Convert]}
3037+ *
3038+ * ### Examples:
3039+ * ```kotlin
3040+ * df.convert { duration }.toDuration()
3041+ * ```
3042+ *
3043+ * @return A new [DataFrame] with the values converted to [Duration].
3044+ */
3045+ @JvmName(" toDurationFromJavaDuration" )
3046+ @Refine
3047+ @Converter(Duration ::class , nullable = false )
3048+ @Interpretable(" ToSpecificType" )
3049+ public fun <T > Convert <T , JavaDuration >.toDuration (): DataFrame <T > = asColumn { it.convertToDuration() }
3050+
3051+ // endregion
3052+
29203053/* *
29213054 * Converts values in the columns previously selected with [convert] to the [Int],
29223055 * preserving their original names and positions within the [DataFrame].
0 commit comments