diff options
-rw-r--r-- | src/include/gnunet_time_lib.h | 16 | ||||
-rw-r--r-- | src/util/time.c | 27 |
2 files changed, 43 insertions, 0 deletions
diff --git a/src/include/gnunet_time_lib.h b/src/include/gnunet_time_lib.h index b9c2d92f0..aa4e8d5db 100644 --- a/src/include/gnunet_time_lib.h +++ b/src/include/gnunet_time_lib.h | |||
@@ -314,6 +314,22 @@ struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_add (struct | |||
314 | GNUNET_TIME_Relative | 314 | GNUNET_TIME_Relative |
315 | duration); | 315 | duration); |
316 | 316 | ||
317 | |||
318 | /** | ||
319 | * Subtract a given relative duration from the | ||
320 | * given start time. | ||
321 | * | ||
322 | * @param start some absolute time | ||
323 | * @param duration some relative time to subtract | ||
324 | * @return ZERO if start <= duration, or FOREVER if start time is FOREVER; start-duration otherwise | ||
325 | */ | ||
326 | struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_subtract (struct | ||
327 | GNUNET_TIME_Absolute | ||
328 | start, | ||
329 | struct | ||
330 | GNUNET_TIME_Relative | ||
331 | duration); | ||
332 | |||
317 | /** | 333 | /** |
318 | * Multiply relative time by a given factor. | 334 | * Multiply relative time by a given factor. |
319 | * | 335 | * |
diff --git a/src/util/time.c b/src/util/time.c index 6eccf4d9a..3d53e0af2 100644 --- a/src/util/time.c +++ b/src/util/time.c | |||
@@ -270,6 +270,33 @@ GNUNET_TIME_absolute_add (struct GNUNET_TIME_Absolute start, | |||
270 | return ret; | 270 | return ret; |
271 | } | 271 | } |
272 | 272 | ||
273 | |||
274 | /** | ||
275 | * Subtract a given relative duration from the | ||
276 | * given start time. | ||
277 | * | ||
278 | * @param start some absolute time | ||
279 | * @param duration some relative time to subtract | ||
280 | * @return ZERO if start <= duration, or FOREVER if start time is FOREVER; start-duration otherwise | ||
281 | */ | ||
282 | struct GNUNET_TIME_Absolute | ||
283 | GNUNET_TIME_absolute_subtract (struct | ||
284 | GNUNET_TIME_Absolute | ||
285 | start, | ||
286 | struct | ||
287 | GNUNET_TIME_Relative | ||
288 | duration) | ||
289 | { | ||
290 | struct GNUNET_TIME_Absolute ret; | ||
291 | if (start.value <= duration.value) | ||
292 | return GNUNET_TIME_UNIT_ZERO_ABS; | ||
293 | if (start.value == GNUNET_TIME_UNIT_FOREVER_ABS.value) | ||
294 | return GNUNET_TIME_UNIT_FOREVER_ABS; | ||
295 | ret.value = start.value - duration.value; | ||
296 | return ret; | ||
297 | } | ||
298 | |||
299 | |||
273 | /** | 300 | /** |
274 | * Multiply relative time by a given factor. | 301 | * Multiply relative time by a given factor. |
275 | * | 302 | * |