-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add klock in common and DateTimeSerializer
- Loading branch information
1 parent
2db0ead
commit 9f7c963
Showing
4 changed files
with
32 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
common/src/commonMain/kotlin/dev/inmo/micro_utils/common/DateTimeSerializer.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters