gnunet-svn
[Top][All Lists]
Advanced

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

[libeufin] branch master updated: Introducing global clock.


From: gnunet
Subject: [libeufin] branch master updated: Introducing global clock.
Date: Wed, 06 Jan 2021 18:08:55 +0100

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

ms pushed a commit to branch master
in repository libeufin.

The following commit(s) were added to refs/heads/master by this push:
     new c6ee1e2  Introducing global clock.
c6ee1e2 is described below

commit c6ee1e2850caeb1724edd0e0ee7137cde5f6e094
Author: MS <ms@taler.net>
AuthorDate: Wed Jan 6 18:08:24 2021 +0100

    Introducing global clock.
---
 util/src/main/kotlin/time.kt     |  9 +++++++++
 util/src/test/kotlin/TimeTest.kt | 13 +++++--------
 2 files changed, 14 insertions(+), 8 deletions(-)

diff --git a/util/src/main/kotlin/time.kt b/util/src/main/kotlin/time.kt
index 6d6e378..86a9f02 100644
--- a/util/src/main/kotlin/time.kt
+++ b/util/src/main/kotlin/time.kt
@@ -22,6 +22,15 @@ package tech.libeufin.util
 import java.time.*
 import java.time.format.DateTimeFormatter
 
+private var LIBEUFIN_CLOCK = Clock.system(ZoneId.systemDefault())
+
+fun setClock(rel: Duration) {
+    LIBEUFIN_CLOCK = Clock.offset(LIBEUFIN_CLOCK, rel)
+}
+fun getNow(): ZonedDateTime {
+    return ZonedDateTime.now(LIBEUFIN_CLOCK)
+}
+
 fun LocalDateTime.toZonedString(): String {
     return 
DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(this.atZone(ZoneId.systemDefault()))
 }
diff --git a/util/src/test/kotlin/TimeTest.kt b/util/src/test/kotlin/TimeTest.kt
index 872fe6a..fd980cb 100644
--- a/util/src/test/kotlin/TimeTest.kt
+++ b/util/src/test/kotlin/TimeTest.kt
@@ -1,4 +1,6 @@
 import org.junit.Test
+import tech.libeufin.util.getNow
+import tech.libeufin.util.setClock
 import java.time.*
 import java.time.format.DateTimeFormatter
 
@@ -7,14 +9,9 @@ import java.time.format.DateTimeFormatter
 class TimeTest {
     @Test
     fun mock() {
-        // Using the system clock, thus not mocking at all.
-        val systemClock = Clock.system(ZoneId.systemDefault())
-        val realNow = ZonedDateTime.now(systemClock)
-        println(realNow)
-        // Moving four hours later.
-        val offsetTime = Clock.offset(systemClock, Duration.ofHours(4))
-        val offesetNow = ZonedDateTime.now(offsetTime)
-        println(offesetNow)
+        println(getNow())
+        setClock(Duration.ofHours(2))
+        println(getNow())
     }
 
     @Test

-- 
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]