add klock in common and DateTimeSerializer

This commit is contained in:
InsanusMokrassar 2024-04-27 15:34:52 +06:00
parent 2db0eadbfe
commit 9f7c963cd5
4 changed files with 32 additions and 1 deletions

View File

@ -2,6 +2,10 @@
## 0.20.46 ## 0.20.46
* `Common`:
* Now this repo depends on `klock`
* Add new object-serializer `DateTimeSerializer` for `klock` serializer
## 0.20.45 ## 0.20.45
* `Versions`: * `Versions`:

View File

@ -8,6 +8,11 @@ apply from: "$mppJvmJsAndroidLinuxMingwLinuxArm64ProjectPresetPath"
kotlin { kotlin {
sourceSets { sourceSets {
commonMain {
dependencies {
api libs.klock
}
}
jvmMain { jvmMain {
dependencies { dependencies {
api project(":micro_utils.coroutines") api project(":micro_utils.coroutines")

View File

@ -0,0 +1,23 @@
package dev.inmo.micro_utils.common
import korlibs.time.DateTime
import kotlinx.serialization.KSerializer
import kotlinx.serialization.Serializer
import kotlinx.serialization.builtins.serializer
import kotlinx.serialization.descriptors.SerialDescriptor
import kotlinx.serialization.encoding.Decoder
import kotlinx.serialization.encoding.Encoder
@Serializer(DateTime::class)
object DateTimeSerializer : KSerializer<DateTime> {
override val descriptor: SerialDescriptor
get() = Double.serializer().descriptor
override fun deserialize(decoder: Decoder): DateTime {
return DateTime(decoder.decodeDouble())
}
override fun serialize(encoder: Encoder, value: DateTime) {
encoder.encodeDouble(value.unixMillis)
}
}

View File

@ -12,7 +12,6 @@ kotlin {
dependencies { dependencies {
api internalProject("micro_utils.common") api internalProject("micro_utils.common")
api libs.kt.serialization.cbor api libs.kt.serialization.cbor
api libs.klock
api libs.uuid api libs.uuid
api libs.ktor.io api libs.ktor.io
} }