2 * Copyright (C) 2004 Internet Systems Consortium, Inc. ("ISC")
3 * Copyright (C) 1998-2001 Internet Software Consortium.
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
9 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
10 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
12 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
14 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15 * PERFORMANCE OF THIS SOFTWARE.
18 /* $Id: time.h,v 1.25.2.1.10.4 2004/03/08 09:04:58 marka Exp $ */
24 #include <isc/types.h>
31 * The contents of this structure are private, and MUST NOT be accessed
32 * directly by callers.
34 * The contents are exposed only to allow callers to avoid dynamic allocation.
38 unsigned int nanoseconds;
41 extern isc_interval_t *isc_interval_zero;
46 isc_interval_set(isc_interval_t *i,
47 unsigned int seconds, unsigned int nanoseconds);
49 * Set 'i' to a value representing an interval of 'seconds' seconds and
50 * 'nanoseconds' nanoseconds, suitable for use in isc_time_add() and
51 * isc_time_subtract().
55 * 't' is a valid pointer.
56 * nanoseconds < 1000000000.
60 isc_interval_iszero(const isc_interval_t *i);
62 * Returns ISC_TRUE iff. 'i' is the zero interval.
66 * 'i' is a valid pointer.
74 * The contents of this structure are private, and MUST NOT be accessed
75 * directly by callers.
77 * The contents are exposed only to allow callers to avoid dynamic allocation.
82 unsigned int nanoseconds;
85 extern isc_time_t *isc_time_epoch;
88 isc_time_set(isc_time_t *t, unsigned int seconds, unsigned int nanoseconds);
90 * Set 't' to a particular number of seconds + nanoseconds since the epoch.
93 * This call is equivalent to:
95 * isc_time_settoepoch(t);
96 * isc_interval_set(i, seconds, nanoseconds);
97 * isc_time_add(t, i, t);
100 * 't' is a valid pointer.
101 * nanoseconds < 1000000000.
105 isc_time_settoepoch(isc_time_t *t);
107 * Set 't' to the time of the epoch.
110 * The date of the epoch is platform-dependent.
114 * 't' is a valid pointer.
118 isc_time_isepoch(const isc_time_t *t);
120 * Returns ISC_TRUE iff. 't' is the epoch ("time zero").
124 * 't' is a valid pointer.
128 isc_time_now(isc_time_t *t);
130 * Set 't' to the current absolute time.
134 * 't' is a valid pointer.
140 * Getting the time from the system failed.
142 * The time from the system is too large to be represented
143 * in the current definition of isc_time_t.
147 isc_time_nowplusinterval(isc_time_t *t, const isc_interval_t *i);
149 * Set *t to the current absolute time + i.
152 * This call is equivalent to:
155 * isc_time_add(t, i, t);
159 * 't' and 'i' are valid pointers.
165 * Getting the time from the system failed.
167 * The interval added to the time from the system is too large to
168 * be represented in the current definition of isc_time_t.
172 isc_time_compare(const isc_time_t *t1, const isc_time_t *t2);
174 * Compare the times referenced by 't1' and 't2'
178 * 't1' and 't2' are valid pointers.
182 * -1 t1 < t2 (comparing times, not pointers)
188 isc_time_add(const isc_time_t *t, const isc_interval_t *i, isc_time_t *result);
190 * Add 'i' to 't', storing the result in 'result'.
194 * 't', 'i', and 'result' are valid pointers.
199 * The interval added to the time is too large to
200 * be represented in the current definition of isc_time_t.
204 isc_time_subtract(const isc_time_t *t, const isc_interval_t *i,
207 * Subtract 'i' from 't', storing the result in 'result'.
211 * 't', 'i', and 'result' are valid pointers.
216 * The interval is larger than the time since the epoch.
220 isc_time_microdiff(const isc_time_t *t1, const isc_time_t *t2);
222 * Find the difference in microseconds between time t1 and time t2.
223 * t2 is the subtrahend of t1; ie, difference = t1 - t2.
227 * 't1' and 't2' are valid pointers.
230 * The difference of t1 - t2, or 0 if t1 <= t2.
234 isc_time_seconds(const isc_time_t *t);
236 * Return the number of seconds since the epoch stored in a time structure.
240 * 't' is a valid pointer.
244 isc_time_secondsastimet(const isc_time_t *t, time_t *secondsp);
246 * Ensure the number of seconds in an isc_time_t is representable by a time_t.
249 * The number of seconds stored in an isc_time_t might be larger
250 * than the number of seconds a time_t is able to handle. Since
251 * time_t is mostly opaque according to the ANSI/ISO standard
252 * (essentially, all you can be sure of is that it is an arithmetic type,
253 * not even necessarily integral), it can be tricky to ensure that
254 * the isc_time_t is in the range a time_t can handle. Use this
255 * function in place of isc_time_seconds() any time you need to set a
256 * time_t from an isc_time_t.
259 * 't' is a valid pointer.
267 isc_time_nanoseconds(const isc_time_t *t);
269 * Return the number of nanoseconds stored in a time structure.
272 * This is the number of nanoseconds in excess of the the number
273 * of seconds since the epoch; it will always be less than one
277 * 't' is a valid pointer.
280 * The returned value is less than 1*10^9.
284 isc_time_formattimestamp(const isc_time_t *t, char *buf, unsigned int len);
286 * Format the time 't' into the buffer 'buf' of length 'len',
287 * using a format like "30-Aug-2000 04:06:47.997" and the local time zone.
288 * If the text does not fit in the buffer, the result is indeterminate,
289 * but is always guaranteed to be null terminated.
293 * 'buf' points to an array of at least len chars
299 #endif /* ISC_TIME_H */