diff options
author | Christian Grothoff <christian@grothoff.org> | 2016-03-17 19:24:35 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2016-03-17 19:24:35 +0000 |
commit | a5361231e36224607d8c2c1376757c0b99f34f59 (patch) | |
tree | ee2ee9fa2c114c6b8e5850f9b31d2bbb54b8c5d2 /src/util/time.c | |
parent | 23b982b51e8f1c152053154c0fce4cfc4cfcbf67 (diff) | |
download | gnunet-a5361231e36224607d8c2c1376757c0b99f34f59.tar.gz gnunet-a5361231e36224607d8c2c1376757c0b99f34f59.zip |
adding library for basic JSON conversions
Diffstat (limited to 'src/util/time.c')
-rw-r--r-- | src/util/time.c | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/src/util/time.c b/src/util/time.c index 4f3eaa7fb..654b567f0 100644 --- a/src/util/time.c +++ b/src/util/time.c | |||
@@ -59,6 +59,46 @@ GNUNET_TIME_get_offset () | |||
59 | 59 | ||
60 | 60 | ||
61 | /** | 61 | /** |
62 | * Round a time value so that it is suitable for transmission | ||
63 | * via JSON encodings. | ||
64 | * | ||
65 | * @param at time to round | ||
66 | * @return #GNUNET_OK if time was already rounded, #GNUNET_NO if | ||
67 | * it was just now rounded | ||
68 | */ | ||
69 | int | ||
70 | GNUNET_TIME_round_abs (struct GNUNET_TIME_Absolute *at) | ||
71 | { | ||
72 | if (at->abs_value_us == GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us) | ||
73 | return GNUNET_OK; | ||
74 | if (0 == at->abs_value_us % 1000000) | ||
75 | return GNUNET_OK; | ||
76 | at->abs_value_us -= at->abs_value_us % 1000000; | ||
77 | return GNUNET_NO; | ||
78 | } | ||
79 | |||
80 | |||
81 | /** | ||
82 | * Round a time value so that it is suitable for transmission | ||
83 | * via JSON encodings. | ||
84 | * | ||
85 | * @param rt time to round | ||
86 | * @return #GNUNET_OK if time was already rounded, #GNUNET_NO if | ||
87 | * it was just now rounded | ||
88 | */ | ||
89 | int | ||
90 | GNUNET_TIME_round_rel (struct GNUNET_TIME_Relative *rt) | ||
91 | { | ||
92 | if (rt->rel_value_us == GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us) | ||
93 | return GNUNET_OK; | ||
94 | if (0 == rt->rel_value_us % 1000000) | ||
95 | return GNUNET_OK; | ||
96 | rt->rel_value_us -= rt->rel_value_us % 1000000; | ||
97 | return GNUNET_NO; | ||
98 | } | ||
99 | |||
100 | |||
101 | /** | ||
62 | * Get the current time (works just as "time", just that we use the | 102 | * Get the current time (works just as "time", just that we use the |
63 | * unit of time that the cron-jobs use (and is 64 bit)). | 103 | * unit of time that the cron-jobs use (and is 64 bit)). |
64 | * | 104 | * |