All Downloads are FREE. Search and download functionalities are using the official Maven repository.

commonMain.krono.LocalDateTimeConstructors.kt Maven / Gradle / Ivy

The newest version!
@file:JsExport
@file:Suppress("NON_EXPORTABLE_TYPE")

package krono

import kase.Result
import kase.catching
import krono.internal.LocalDateTimeImpl
import kotlinx.JsExport
import kotlin.js.JsName
import kotlin.jvm.JvmOverloads

@JsName("localDateTimeFromDateAndTime")
@JvmOverloads
fun LocalDateTime(date: LocalDate,time: LocalTime): Result = catching {
    LocalDateTimeImpl(date, time)
}

@JsName("localDateTime")
@JvmOverloads
fun LocalDateTime(year: Int = 1970, month: Int = 1, dayOfMonth: Int = 1, hour: Int = 0, minutes: Int = 0, seconds: Int = 0, nanoseconds: Int = 0): Result = catching {
    val date = LocalDate(year, month, dayOfMonth).getOrThrow()
    val time = LocalTime(hour, minutes, seconds, nanoseconds).getOrThrow()
    LocalDateTimeImpl(date, time)
}

@JsName("localDateTimeEpoch")
inline fun LocalDateTimeEpoch(): LocalDateTime = LocalDateTimeImpl(LocalDateEpoch(), Midnight())

@JsName("parseLocalDateTime")
fun LocalDateTime(isoString: String?): Result = catching{
    val iso = isoString ?: throw IllegalArgumentException("isoString can't be null")
    val date = LocalDate(iso).getOrThrow()
    val time = LocalTimeOrMidnight(iso.split("T").getOrNull(1) ?: "")
    LocalDateTimeImpl(date, time)
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy