aboutsummaryrefslogtreecommitdiff
path: root/src/include/gnunet_time_lib.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/include/gnunet_time_lib.h')
-rw-r--r--src/include/gnunet_time_lib.h62
1 files changed, 59 insertions, 3 deletions
diff --git a/src/include/gnunet_time_lib.h b/src/include/gnunet_time_lib.h
index b14439462..88dafc62c 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
@@ -19,6 +19,10 @@
19 */ 19 */
20 20
21/** 21/**
22 * @addtogroup libgnunetutil
23 * Multi-function utilities library for GNUnet programs
24 * @{
25 *
22 * @author Christian Grothoff 26 * @author Christian Grothoff
23 * 27 *
24 * @file 28 * @file
@@ -40,6 +44,7 @@ extern "C"
40#endif 44#endif
41#endif 45#endif
42 46
47
43#include "gnunet_common.h" 48#include "gnunet_common.h"
44 49
45/** 50/**
@@ -238,7 +243,7 @@ GNUNET_TIME_timestamp2s (struct GNUNET_TIME_Timestamp ts);
238 * Note that the returned value will be overwritten if this function 243 * Note that the returned value will be overwritten if this function
239 * is called again. 244 * is called again.
240 * 245 *
241 * @param t the absolute time to convert 246 * @param ts the absolute time to convert
242 * @return timestamp in human-readable form in local time 247 * @return timestamp in human-readable form in local time
243 */ 248 */
244const char * 249const char *
@@ -482,6 +487,18 @@ GNUNET_TIME_absolute_max (struct GNUNET_TIME_Absolute t1,
482 487
483 488
484/** 489/**
490 * Round down absolute time @a at to multiple of @a rt.
491 *
492 * @param at absolute time to round
493 * @param rt multiple to round to (non-zero)
494 * @return rounded time
495 */
496struct GNUNET_TIME_Absolute
497GNUNET_TIME_absolute_round_down (struct GNUNET_TIME_Absolute at,
498 struct GNUNET_TIME_Relative rt);
499
500
501/**
485 * Return the maximum of two timestamps. 502 * Return the maximum of two timestamps.
486 * 503 *
487 * @param t1 first timestamp 504 * @param t1 first timestamp
@@ -517,6 +534,21 @@ GNUNET_TIME_absolute_get_remaining (struct GNUNET_TIME_Absolute future);
517 534
518 535
519/** 536/**
537 * Test if @a a1 and @a a2 are equal within a margin of
538 * error of @a t.
539 *
540 * @param a1 time to compare
541 * @param a2 time to compare
542 * @param t tolerance to apply
543 * @return true if "|a1-a2|<=t" holds.
544 */
545bool
546GNUNET_TIME_absolute_approx_eq (struct GNUNET_TIME_Absolute a1,
547 struct GNUNET_TIME_Absolute a2,
548 struct GNUNET_TIME_Relative t);
549
550
551/**
520 * Calculate the estimate time of arrival/completion 552 * Calculate the estimate time of arrival/completion
521 * for an operation. 553 * for an operation.
522 * 554 *
@@ -587,6 +619,17 @@ GNUNET_TIME_absolute_subtract (struct GNUNET_TIME_Absolute start,
587 * Multiply relative time by a given factor. 619 * Multiply relative time by a given factor.
588 * 620 *
589 * @param rel some duration 621 * @param rel some duration
622 * @param factor double to multiply with
623 * @return FOREVER if rel=FOREVER or on overflow; otherwise rel*factor
624 */
625struct GNUNET_TIME_Relative
626GNUNET_TIME_relative_multiply_double (struct GNUNET_TIME_Relative rel,
627 double factor);
628
629/**
630 * Multiply relative time by a given factor.
631 *
632 * @param rel some duration
590 * @param factor integer to multiply with 633 * @param factor integer to multiply with
591 * @return FOREVER if rel=FOREVER or on overflow; otherwise rel*factor 634 * @return FOREVER if rel=FOREVER or on overflow; otherwise rel*factor
592 */ 635 */
@@ -762,11 +805,22 @@ GNUNET_TIME_absolute_from_s (uint64_t s_after_epoch);
762 * 805 *
763 * @param s_after_epoch seconds after epoch to convert 806 * @param s_after_epoch seconds after epoch to convert
764 * @return converted time value 807 * @return converted time value
765 */struct GNUNET_TIME_Timestamp 808 */
809struct GNUNET_TIME_Timestamp
766GNUNET_TIME_timestamp_from_s (uint64_t s_after_epoch); 810GNUNET_TIME_timestamp_from_s (uint64_t s_after_epoch);
767 811
768 812
769/** 813/**
814 * Convert timestamp to number of seconds after the UNIX epoch.
815 *
816 * @param ts timestamp to convert
817 * @return converted time value
818 */
819uint64_t
820GNUNET_TIME_timestamp_to_s (struct GNUNET_TIME_Timestamp ts);
821
822
823/**
770 * Convert absolute time from network byte order. 824 * Convert absolute time from network byte order.
771 * 825 *
772 * @param a time to convert 826 * @param a time to convert
@@ -872,4 +926,6 @@ GNUNET_TIME_absolute_get_monotonic (
872 926
873/** @} */ /* end of group time */ 927/** @} */ /* end of group time */
874 928
929/** @} */ /* end of group addition */
930
875/* end of gnunet_time_lib.h */ 931/* end of gnunet_time_lib.h */