File tree Expand file tree Collapse file tree 2 files changed +10
-0
lines changed
core/src/main/kotlin/io/github/rothes/esu/core/configuration/serializer Expand file tree Collapse file tree 2 files changed +10
-0
lines changed Original file line number Diff line number Diff line change @@ -5,11 +5,16 @@ import io.github.rothes.esu.lib.org.spongepowered.configurate.serialize.Serializ
55import java.lang.reflect.Type
66import java.util.function.Predicate
77import kotlin.time.Duration
8+ import kotlin.time.Duration.Companion.milliseconds
89
910object DurationSerializer: ScalarSerializer<Duration>(Duration : :class.java) {
1011
1112 @Throws(SerializationException ::class )
1213 override fun deserialize (type : Type , obj : Any ): Duration {
14+ when (obj) {
15+ is Long -> return obj.milliseconds
16+ is Int -> return obj.milliseconds
17+ }
1318 val string = obj.toString()
1419 return Duration .parse(string)
1520 }
Original file line number Diff line number Diff line change @@ -5,13 +5,18 @@ import io.github.rothes.esu.lib.org.spongepowered.configurate.serialize.Serializ
55import java.lang.reflect.Type
66import java.time.Duration
77import java.util.function.Predicate
8+ import kotlin.time.Duration.Companion.milliseconds
89import kotlin.time.toJavaDuration
910import kotlin.time.toKotlinDuration
1011
1112object JavaDurationSerializer: ScalarSerializer<Duration>(Duration : :class.java) {
1213
1314 @Throws(SerializationException ::class )
1415 override fun deserialize (type : Type , obj : Any ): Duration {
16+ when (obj) {
17+ is Long -> return Duration .ofMillis(obj)
18+ is Int -> return Duration .ofMillis(obj.toLong())
19+ }
1520 val string = obj.toString()
1621 return kotlin.time.Duration .parse(string).toJavaDuration()
1722 }
You can’t perform that action at this time.
0 commit comments