2 This file is part of GNUnet.
3 (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2009 Christian Grothoff (and other contributing authors)
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 2, or (at your
8 option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
22 * @file include/gnunet_time_lib.h
23 * @brief functions related to time
25 * @author Christian Grothoff
28 #ifndef GNUNET_TIME_LIB_H
29 #define GNUNET_TIME_LIB_H
34 #if 0 /* keep Emacsens' auto-indent happy */
39 #include "gnunet_common.h"
42 * Time for absolute times used by GNUnet, in milliseconds.
44 struct GNUNET_TIME_Absolute
50 * Time for relative time used by GNUnet, in milliseconds.
51 * Always positive, so we can only refer to future time.
53 struct GNUNET_TIME_Relative
60 * Time for relative time used by GNUnet, in milliseconds and in network byte order.
62 struct GNUNET_TIME_RelativeNBO
64 uint64_t value GNUNET_PACKED;
69 * Time for absolute time used by GNUnet, in milliseconds and in network byte order.
71 struct GNUNET_TIME_AbsoluteNBO
73 uint64_t value GNUNET_PACKED;
77 * @brief constants to specify time
79 #define GNUNET_TIME_UNIT_ZERO GNUNET_TIME_relative_get_zero()
80 #define GNUNET_TIME_UNIT_MILLISECONDS GNUNET_TIME_relative_get_unit()
81 #define GNUNET_TIME_UNIT_SECONDS GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 1000)
82 #define GNUNET_TIME_UNIT_MINUTES GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 60)
83 #define GNUNET_TIME_UNIT_HOURS GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 60)
84 #define GNUNET_TIME_UNIT_DAYS GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_HOURS, 24)
85 #define GNUNET_TIME_UNIT_WEEKS GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_DAYS, 7)
86 #define GNUNET_TIME_UNIT_MONTHS GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_DAYS, 30)
87 #define GNUNET_TIME_UNIT_YEARS GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_DAYS, 365)
90 * Constant used to specify "forever". This constant
91 * will be treated specially in all time operations.
93 #define GNUNET_TIME_UNIT_FOREVER_REL GNUNET_TIME_relative_get_forever ()
96 * Constant used to specify "forever". This constant
97 * will be treated specially in all time operations.
99 #define GNUNET_TIME_UNIT_FOREVER_ABS GNUNET_TIME_absolute_get_forever ()
102 * Return relative time of 0ms.
104 struct GNUNET_TIME_Relative GNUNET_TIME_relative_get_zero (void);
107 * Return relative time of 1ms.
109 struct GNUNET_TIME_Relative GNUNET_TIME_relative_get_unit (void);
114 struct GNUNET_TIME_Relative GNUNET_TIME_relative_get_forever (void);
119 struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get_forever (void);
122 * Get the current time.
124 * @return the current time
126 struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get (void);
129 * Convert relative time to an absolute time in the
132 * @return timestamp that is "rel" in the future, or FOREVER if rel==FOREVER (or if we would overflow)
134 struct GNUNET_TIME_Absolute GNUNET_TIME_relative_to_absolute (struct
139 * Given a timestamp in the future, how much time
140 * remains until then?
142 * @return future - now, or 0 if now >= future, or FOREVER if future==FOREVER.
144 struct GNUNET_TIME_Relative GNUNET_TIME_absolute_get_remaining (struct
149 * Compute the time difference between the given start and end times.
150 * Use this function instead of actual subtraction to ensure that
151 * "FOREVER" and overflows are handeled correctly.
153 * @return 0 if start >= end; FOREVER if end==FOREVER; otherwise end - start
155 struct GNUNET_TIME_Relative GNUNET_TIME_absolute_get_difference (struct
163 * Get the duration of an operation as the
164 * difference of the current time and the given start time "hence".
166 * @return aborts if hence==FOREVER, 0 if hence > now, otherwise now-hence.
168 struct GNUNET_TIME_Relative GNUNET_TIME_absolute_get_duration (struct
174 * Add a given relative duration to the
177 * @return FOREVER if either argument is FOREVER or on overflow; start+duration otherwise
179 struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_add (struct
187 * Multiply relative time by a given factor.
189 * @return FOREVER if rel=FOREVER or on overflow; otherwise rel*factor
191 struct GNUNET_TIME_Relative GNUNET_TIME_relative_multiply (struct
198 * Add relative times together.
200 * @return FOREVER if either argument is FOREVER or on overflow; a1+a2 otherwise
202 struct GNUNET_TIME_Relative GNUNET_TIME_relative_add (struct
203 GNUNET_TIME_Relative a1,
210 * Convert relative time to network byte order.
212 struct GNUNET_TIME_RelativeNBO GNUNET_TIME_relative_hton (struct
217 * Convert relative time from network byte order.
219 struct GNUNET_TIME_Relative GNUNET_TIME_relative_ntoh (struct
220 GNUNET_TIME_RelativeNBO
224 * Convert relative time to network byte order.
226 struct GNUNET_TIME_AbsoluteNBO GNUNET_TIME_absolute_hton (struct
231 * Convert relative time from network byte order.
233 struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_ntoh (struct
234 GNUNET_TIME_AbsoluteNBO
237 #if 0 /* keep Emacsens' auto-indent happy */
244 /* ifndef GNUNET_TIME_LIB_H */
246 /* end of gnunet_time_lib.h */