mirror of
https://github.com/InsanusMokrassar/MicroUtils.git
synced 2024-11-17 13:53:49 +00:00
migration onto datetime
This commit is contained in:
parent
2a783f6e2b
commit
44e26ccb4f
@ -2,6 +2,11 @@
|
||||
|
||||
## 0.6.0
|
||||
|
||||
**THIS VERSION HAS MIGRATED FROM KORLIBS KLOCK TO KOTLINX DATETIME. CAREFUL**
|
||||
|
||||
* `Versions`
|
||||
* `Klock` -> `kotlinx.datetime`
|
||||
|
||||
## 0.5.31
|
||||
|
||||
* `Versions`:
|
||||
|
@ -14,7 +14,7 @@ kotlin_exposed_version=0.35.1
|
||||
|
||||
ktor_version=1.6.4
|
||||
|
||||
klockVersion=2.4.3
|
||||
datetime_version=0.3.0
|
||||
|
||||
github_release_plugin_version=2.2.12
|
||||
|
||||
|
@ -11,7 +11,7 @@ kotlin {
|
||||
commonMain {
|
||||
dependencies {
|
||||
api "org.jetbrains.kotlinx:kotlinx-serialization-cbor:$kotlin_serialisation_core_version"
|
||||
api "com.soywiz.korlibs.klock:klock:$klockVersion"
|
||||
api "org.jetbrains.kotlinx:kotlinx-datetime:$datetime_version"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,17 +1,17 @@
|
||||
package dev.inmo.micro_utils.ktor.common
|
||||
|
||||
import com.soywiz.klock.DateTime
|
||||
import kotlinx.datetime.Instant
|
||||
|
||||
typealias FromToDateTime = Pair<DateTime?, DateTime?>
|
||||
typealias FromToDateTime = Pair<Instant?, Instant?>
|
||||
|
||||
val FromToDateTime.asFromToUrlPart: QueryParams
|
||||
get() = mapOf(
|
||||
"from" to first ?.unixMillis ?.toString(),
|
||||
"to" to second ?.unixMillis ?.toString()
|
||||
"from" to first ?.toEpochMilliseconds() ?.toString(),
|
||||
"to" to second ?.toEpochMilliseconds() ?.toString()
|
||||
)
|
||||
|
||||
val QueryParams.extractFromToDateTime: FromToDateTime
|
||||
get() = FromToDateTime(
|
||||
get("from") ?.toDoubleOrNull() ?.let { DateTime(it) },
|
||||
get("to") ?.toDoubleOrNull() ?.let { DateTime(it) }
|
||||
get("from") ?.run { toLongOrNull() ?: (toDoubleOrNull() ?.toLong()) } ?.let { Instant.fromEpochMilliseconds(it) },
|
||||
get("to") ?.run { toLongOrNull() ?: (toDoubleOrNull() ?.toLong()) } ?.let { Instant.fromEpochMilliseconds(it) }
|
||||
)
|
||||
|
@ -1,11 +1,11 @@
|
||||
package dev.inmo.micro_utils.ktor.server
|
||||
|
||||
import com.soywiz.klock.DateTime
|
||||
import dev.inmo.micro_utils.ktor.common.FromToDateTime
|
||||
import io.ktor.http.Parameters
|
||||
import kotlinx.datetime.Instant
|
||||
|
||||
val Parameters.extractFromToDateTime: FromToDateTime
|
||||
get() = FromToDateTime(
|
||||
get("from") ?.toDoubleOrNull() ?.let { DateTime(it) },
|
||||
get("to") ?.toDoubleOrNull() ?.let { DateTime(it) }
|
||||
get("from") ?.run { toLongOrNull() ?: (toDoubleOrNull() ?.toLong()) } ?.let { Instant.fromEpochMilliseconds(it) },
|
||||
get("to") ?.run { toLongOrNull() ?: (toDoubleOrNull() ?.toLong()) } ?.let { Instant.fromEpochMilliseconds(it) }
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user