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

commonMain.dev.inmo.micro_utils.common.DateTimeSerializer.kt Maven / Gradle / Ivy

The newest version!
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

/**
 * Serializes [DateTime] as its raw [DateTime.unixMillis] and deserializes in the same way
 */
object DateTimeSerializer : KSerializer {
    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)
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy