summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian <sebasjm@gmail.com>2022-05-11 11:58:16 -0300
committerSebastian <sebasjm@gmail.com>2022-05-11 11:58:16 -0300
commitcb92566166884efdaad5e93ef25e2de1f3034616 (patch)
treee5d9430d01a4ab80bf5ec2bc630419252edb4c58
parent6f698f4d0ef580a898d3b03e9e8954af4f194037 (diff)
downloadwallet-kotlin-master.tar.gz
wallet-kotlin-master.tar.bz2
wallet-kotlin-master.zip
add support to the new timestamp formatHEADmaster
-rw-r--r--.gitignore3
-rw-r--r--common/src/commonMain/kotlin/net/taler/lib/common/Time.kt37
2 files changed, 35 insertions, 5 deletions
diff --git a/.gitignore b/.gitignore
index 4d47fee..d3b37e6 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,6 @@
/build
/.gradle
/local.properties
+.settings
+.project
+.classpath
diff --git a/common/src/commonMain/kotlin/net/taler/lib/common/Time.kt b/common/src/commonMain/kotlin/net/taler/lib/common/Time.kt
index 704a91a..1ed54b5 100644
--- a/common/src/commonMain/kotlin/net/taler/lib/common/Time.kt
+++ b/common/src/commonMain/kotlin/net/taler/lib/common/Time.kt
@@ -17,8 +17,12 @@
package net.taler.lib.common
import com.soywiz.klock.DateTime
+import kotlinx.serialization.Contextual
+import kotlinx.serialization.KSerializer
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
+import kotlinx.serialization.Transient
+import kotlinx.serialization.builtins.nullable
import kotlinx.serialization.builtins.serializer
import kotlinx.serialization.json.JsonElement
import kotlinx.serialization.json.JsonPrimitive
@@ -33,15 +37,29 @@ import kotlin.math.max
public data class Timestamp(
@SerialName("t_ms")
@Serializable(NeverSerializer::class)
- val ms: Long
+ public val old_ms: Long? = null,
+ @SerialName("t_s")
+ @Serializable(NeverSerializer::class)
+ private val s: Long? = null,
) : Comparable<Timestamp> {
+ public constructor(ms: Long) : this(ms, null) {}
+
public companion object {
private const val NEVER: Long = -1
public fun now(): Timestamp = Timestamp(DateTime.nowUnixLong())
public fun never(): Timestamp = Timestamp(NEVER)
}
+ val ms: Long = if (s != null) {
+ s * 1000L
+ } else if (old_ms !== null) {
+ old_ms
+ } else {
+ throw Exception("timestamp didn't have t_s or t_ms")
+ };
+
+
/**
* Returns a copy of this [Timestamp] rounded to seconds.
*/
@@ -77,13 +95,22 @@ public data class Timestamp(
@Serializable
public data class Duration(
- /**
- * Duration in milliseconds.
- */
@SerialName("d_ms")
@Serializable(ForeverSerializer::class)
- val ms: Long
+ public val old_ms: Long? = null,
+ @SerialName("d_s")
+ @Serializable(ForeverSerializer::class)
+ private val s: Long? = null,
) {
+ val ms: Long = if (s != null) {
+ s * 1000L
+ } else if (old_ms !== null) {
+ old_ms
+ } else {
+ throw Exception("duration didn't have d_s or d_ms")
+ };
+ public constructor(ms: Long) : this(ms, null) {}
+
public companion object {
internal const val FOREVER: Long = -1
public fun forever(): Duration = Duration(FOREVER)