diff options
-rw-r--r-- | src/include/gnunet_time_lib.h | 12 | ||||
-rw-r--r-- | src/util/time.c | 14 |
2 files changed, 26 insertions, 0 deletions
diff --git a/src/include/gnunet_time_lib.h b/src/include/gnunet_time_lib.h index 55af62b72..d59eb984d 100644 --- a/src/include/gnunet_time_lib.h +++ b/src/include/gnunet_time_lib.h | |||
@@ -482,6 +482,18 @@ GNUNET_TIME_absolute_max (struct GNUNET_TIME_Absolute t1, | |||
482 | 482 | ||
483 | 483 | ||
484 | /** | 484 | /** |
485 | * Round down absolute time @a at to multiple of @a rt. | ||
486 | * | ||
487 | * @param at absolute time to round | ||
488 | * @param rt multiple to round to (non-zero) | ||
489 | * @return rounded time | ||
490 | */ | ||
491 | struct GNUNET_TIME_Absolute | ||
492 | GNUNET_TIME_absolute_round_down (struct GNUNET_TIME_Absolute at, | ||
493 | struct GNUNET_TIME_Relative rt); | ||
494 | |||
495 | |||
496 | /** | ||
485 | * Return the maximum of two timestamps. | 497 | * Return the maximum of two timestamps. |
486 | * | 498 | * |
487 | * @param t1 first timestamp | 499 | * @param t1 first timestamp |
diff --git a/src/util/time.c b/src/util/time.c index aeec2b3f9..cf072aebf 100644 --- a/src/util/time.c +++ b/src/util/time.c | |||
@@ -386,6 +386,20 @@ GNUNET_TIME_timestamp_min (struct GNUNET_TIME_Timestamp t1, | |||
386 | } | 386 | } |
387 | 387 | ||
388 | 388 | ||
389 | struct GNUNET_TIME_Absolute | ||
390 | GNUNET_TIME_absolute_round_down (struct GNUNET_TIME_Absolute at, | ||
391 | struct GNUNET_TIME_Relative rt) | ||
392 | { | ||
393 | struct GNUNET_TIME_Absolute ret; | ||
394 | |||
395 | GNUNET_assert (! GNUNET_TIME_relative_is_zero (rt)); | ||
396 | ret.abs_value_us | ||
397 | = at.abs_value_us | ||
398 | - at.abs_value_us % rt.rel_value_us; | ||
399 | return ret; | ||
400 | } | ||
401 | |||
402 | |||
389 | struct GNUNET_TIME_Relative | 403 | struct GNUNET_TIME_Relative |
390 | GNUNET_TIME_absolute_get_remaining (struct GNUNET_TIME_Absolute future) | 404 | GNUNET_TIME_absolute_get_remaining (struct GNUNET_TIME_Absolute future) |
391 | { | 405 | { |