[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnunet] branch master updated: introduce new TIME helper functions
From: |
gnunet |
Subject: |
[gnunet] branch master updated: introduce new TIME helper functions |
Date: |
Fri, 23 Jul 2021 20:10:58 +0200 |
This is an automated email from the git hooks/post-receive script.
grothoff pushed a commit to branch master
in repository gnunet.
The following commit(s) were added to refs/heads/master by this push:
new d44f867e7 introduce new TIME helper functions
d44f867e7 is described below
commit d44f867e71e13be3970e8803e0ae238e8d3ed7ee
Author: Christian Grothoff <christian@grothoff.org>
AuthorDate: Fri Jul 23 20:07:44 2021 +0200
introduce new TIME helper functions
---
src/include/gnunet_time_lib.h | 42 ++++++++++++++++++++++++++++++++++++++++--
src/util/time.c | 41 +++++++++++++++++++++++++++++++++++++++++
2 files changed, 81 insertions(+), 2 deletions(-)
diff --git a/src/include/gnunet_time_lib.h b/src/include/gnunet_time_lib.h
index b9e87fcbe..bddf5c6bf 100644
--- a/src/include/gnunet_time_lib.h
+++ b/src/include/gnunet_time_lib.h
@@ -529,6 +529,44 @@ struct GNUNET_TIME_AbsoluteNBO
GNUNET_TIME_absolute_hton (struct GNUNET_TIME_Absolute a);
+/**
+ * Convert milliseconds after the UNIX epoch to absolute time.
+ *
+ * @param ms_after_epoch millisecond timestamp to convert
+ * @return converted time value
+ */
+struct GNUNET_TIME_Absolute
+GNUNET_TIME_absolute_from_ms (uint64_t ms_after_epoch);
+
+
+/**
+ * Test if @a abs is never.
+ *
+ * @return true if it is.
+ */
+bool
+GNUNET_TIME_absolute_is_never (struct GNUNET_TIME_Absolute abs);
+
+
+/**
+ * Test if @a rel is forever.
+ *
+ * @return true if it is.
+ */
+bool
+GNUNET_TIME_relative_is_forever (struct GNUNET_TIME_Relative rel);
+
+
+/**
+ * Convert seconds after the UNIX epoch to absolute time.
+ *
+ * @param s_after_epoch seconds after epoch to convert
+ * @return converted time value
+ */
+struct GNUNET_TIME_Absolute
+GNUNET_TIME_absolute_from_s (uint64_t s_after_epoch);
+
+
/**
* Convert absolute time from network byte order.
*
@@ -609,8 +647,8 @@ struct GNUNET_CONFIGURATION_Handle;
* @return monotonically increasing time
*/
struct GNUNET_TIME_Absolute
-GNUNET_TIME_absolute_get_monotonic (const struct
- GNUNET_CONFIGURATION_Handle *cfg);
+GNUNET_TIME_absolute_get_monotonic (
+ const struct GNUNET_CONFIGURATION_Handle *cfg);
#if 0 /* keep Emacsens' auto-indent happy */
diff --git a/src/util/time.c b/src/util/time.c
index 456ee660b..15a4160e2 100644
--- a/src/util/time.c
+++ b/src/util/time.c
@@ -470,6 +470,47 @@ GNUNET_TIME_absolute_hton (struct GNUNET_TIME_Absolute a)
}
+bool
+GNUNET_TIME_absolute_is_never (struct GNUNET_TIME_Absolute abs)
+{
+ return abs.abs_value_us == GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us;
+}
+
+
+bool
+GNUNET_TIME_relative_is_forever (struct GNUNET_TIME_Relative rel)
+{
+ return rel.rel_value_us == GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us;
+}
+
+
+struct GNUNET_TIME_Absolute
+GNUNET_TIME_absolute_from_ms (uint64_t ms_after_epoch)
+{
+ struct GNUNET_TIME_Absolute ret;
+
+ ret.abs_value_us = GNUNET_TIME_UNIT_MILLISECONDS.rel_value_us
+ * ms_after_epoch;
+ if (ret.abs_value_us / GNUNET_TIME_UNIT_MILLISECONDS.rel_value_us !=
+ ms_after_epoch)
+ ret = GNUNET_TIME_UNIT_FOREVER_ABS;
+ return ret;
+}
+
+
+struct GNUNET_TIME_Absolute
+GNUNET_TIME_absolute_from_s (uint64_t s_after_epoch)
+{
+ struct GNUNET_TIME_Absolute ret;
+
+ ret.abs_value_us = GNUNET_TIME_UNIT_SECONDS.rel_value_us * s_after_epoch;
+ if (ret.abs_value_us / GNUNET_TIME_UNIT_SECONDS.rel_value_us !=
+ s_after_epoch)
+ ret = GNUNET_TIME_UNIT_FOREVER_ABS;
+ return ret;
+}
+
+
struct GNUNET_TIME_Absolute
GNUNET_TIME_absolute_ntoh (struct GNUNET_TIME_AbsoluteNBO a)
{
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.
- [gnunet] branch master updated: introduce new TIME helper functions,
gnunet <=