Skip to content

Commit

Permalink
Add functions for DatePeriod decoding
Browse files Browse the repository at this point in the history
Introduce `asDatePeriod` and `asDatePeriodOrNull` to decode DatePeriod values from ResultSet columns. This enhances the library's ability to handle date period representations directly.
  • Loading branch information
smyrgeorge committed Oct 6, 2024
1 parent 29305df commit 0c201cf
Showing 1 changed file with 3 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package io.github.smyrgeorge.sqlx4k.impl.extensions

import io.github.smyrgeorge.sqlx4k.ResultSet
import io.github.smyrgeorge.sqlx4k.SQLError
import kotlinx.datetime.DatePeriod
import kotlinx.datetime.DateTimePeriod
import kotlinx.datetime.Instant
import kotlinx.datetime.LocalDate
Expand Down Expand Up @@ -52,5 +53,7 @@ fun ResultSet.Row.Column.asLocalDateTime(): LocalDateTime = LocalDateTime.parse(
fun ResultSet.Row.Column.asLocalDateTimeOrNull(): LocalDateTime? = asStringOrNull()?.let { LocalDateTime.parse(it.fixTime()) }
fun ResultSet.Row.Column.asInstant(): Instant = Instant.parse(asString())
fun ResultSet.Row.Column.asInstantOrNull(): Instant? = asStringOrNull()?.let { Instant.parse(it) }
fun ResultSet.Row.Column.asDatePeriod(): DatePeriod = DatePeriod.parse(asString())
fun ResultSet.Row.Column.asDatePeriodOrNull(): DatePeriod? = asStringOrNull()?.let { DatePeriod.parse(it) }
fun ResultSet.Row.Column.asDateTimePeriod(): DateTimePeriod = DateTimePeriod.parse(asString())
fun ResultSet.Row.Column.asDateTimePeriodOrNull(): DateTimePeriod? = asStringOrNull()?.let { DateTimePeriod.parse(it) }

0 comments on commit 0c201cf

Please sign in to comment.