gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[taler-wallet-kotlin] branch master updated: add support to the new time


From: gnunet
Subject: [taler-wallet-kotlin] branch master updated: add support to the new timestamp format
Date: Wed, 11 May 2022 17:03:48 +0200

This is an automated email from the git hooks/post-receive script.

sebasjm pushed a commit to branch master
in repository wallet-kotlin.

The following commit(s) were added to refs/heads/master by this push:
     new cb92566  add support to the new timestamp format
cb92566 is described below

commit cb92566166884efdaad5e93ef25e2de1f3034616
Author: Sebastian <sebasjm@gmail.com>
AuthorDate: Wed May 11 11:58:16 2022 -0300

    add support to the new timestamp format
---
 .gitignore                                         |  3 ++
 .../commonMain/kotlin/net/taler/lib/common/Time.kt | 37 +++++++++++++++++++---
 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)

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]