diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/include/gnunet_time_lib.h | 17 | ||||
-rw-r--r-- | src/util/time.c | 16 |
2 files changed, 32 insertions, 1 deletions
diff --git a/src/include/gnunet_time_lib.h b/src/include/gnunet_time_lib.h index 96413c3cc..55af62b72 100644 --- a/src/include/gnunet_time_lib.h +++ b/src/include/gnunet_time_lib.h | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2001-2013 GNUnet e.V. | 3 | Copyright (C) 2001-2022 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software: you can redistribute it and/or modify it | 5 | GNUnet is free software: you can redistribute it and/or modify it |
6 | under the terms of the GNU Affero General Public License as published | 6 | under the terms of the GNU Affero General Public License as published |
@@ -517,6 +517,21 @@ GNUNET_TIME_absolute_get_remaining (struct GNUNET_TIME_Absolute future); | |||
517 | 517 | ||
518 | 518 | ||
519 | /** | 519 | /** |
520 | * Test if @a a1 and @a a2 are equal within a margin of | ||
521 | * error of @a t. | ||
522 | * | ||
523 | * @param a1 time to compare | ||
524 | * @param a2 time to compare | ||
525 | * @param t tolerance to apply | ||
526 | * @return true if "|a1-a2|<=t" holds. | ||
527 | */ | ||
528 | bool | ||
529 | GNUNET_TIME_absolute_approx_eq (struct GNUNET_TIME_Absolute a1, | ||
530 | struct GNUNET_TIME_Absolute a2, | ||
531 | struct GNUNET_TIME_Relative t); | ||
532 | |||
533 | |||
534 | /** | ||
520 | * Calculate the estimate time of arrival/completion | 535 | * Calculate the estimate time of arrival/completion |
521 | * for an operation. | 536 | * for an operation. |
522 | * | 537 | * |
diff --git a/src/util/time.c b/src/util/time.c index 68a6937a0..aeec2b3f9 100644 --- a/src/util/time.c +++ b/src/util/time.c | |||
@@ -58,6 +58,22 @@ GNUNET_TIME_get_offset () | |||
58 | } | 58 | } |
59 | 59 | ||
60 | 60 | ||
61 | bool | ||
62 | GNUNET_TIME_absolute_approx_eq (struct GNUNET_TIME_Absolute a1, | ||
63 | struct GNUNET_TIME_Absolute a2, | ||
64 | struct GNUNET_TIME_Relative t) | ||
65 | { | ||
66 | struct GNUNET_TIME_Relative delta; | ||
67 | |||
68 | delta = GNUNET_TIME_relative_min ( | ||
69 | GNUNET_TIME_absolute_get_difference (a1, a2), | ||
70 | GNUNET_TIME_absolute_get_difference (a2, a1)); | ||
71 | return GNUNET_TIME_relative_cmp (delta, | ||
72 | <=, | ||
73 | t); | ||
74 | } | ||
75 | |||
76 | |||
61 | struct GNUNET_TIME_Timestamp | 77 | struct GNUNET_TIME_Timestamp |
62 | GNUNET_TIME_absolute_to_timestamp (struct GNUNET_TIME_Absolute at) | 78 | GNUNET_TIME_absolute_to_timestamp (struct GNUNET_TIME_Absolute at) |
63 | { | 79 | { |