xyz.cssxsh.arknights.TimestampSerializer.kt Maven / Gradle / Ivy
package xyz.cssxsh.arknights
import kotlinx.serialization.*
import kotlinx.serialization.descriptors.*
import kotlinx.serialization.encoding.*
import java.time.*
internal object TimestampSerializer : KSerializer {
fun timestamp(second: Long): OffsetDateTime {
return OffsetDateTime.ofInstant(Instant.ofEpochSecond(second), ZoneId.systemDefault())
}
override val descriptor: SerialDescriptor =
PrimitiveSerialDescriptor(OffsetDateTime::class.qualifiedName!!, PrimitiveKind.LONG)
override fun deserialize(decoder: Decoder): OffsetDateTime {
return timestamp(decoder.decodeLong())
}
override fun serialize(encoder: Encoder, value: OffsetDateTime) {
encoder.encodeLong(value.toEpochSecond())
}
}