1 #ifndef EL__UTIL_TIME_H
2 #define EL__UTIL_TIME_H
4 #ifdef HAVE_SYS_TYPES_H
14 typedef long milliseconds_T
;
15 #define MILLISECONDS_MAX ((milliseconds_T) (LONG_MAX / 1000L))
16 #define ms_max(a, b) ((a) < (b) ? (b) : (a))
17 #define ms_min(a, b) ((a) < (b) ? (a) : (b))
19 /** @bug 923: Assumes time_t values fit in @c long. */
20 #define str_to_time_t(s) ((time_t) atol(s))
21 /** When formatting time_t values to be parsed with str_to_time_t(),
22 * we first cast to @c time_print_T and then printf() the result with
23 * ::TIME_PRINT_FORMAT.
24 * @bug 923: Assumes time_t values fit in @c long. */
25 typedef long time_print_T
;
26 #define TIME_PRINT_FORMAT "ld" /**< @see time_print_T */
28 /** Redefine a timeval that has all fields signed so calculations
29 * will be simplified on rare systems that define timeval with
31 * @bug 923: Assumes time_t values fit in long. (This structure is
32 * used for both timestamps and durations.) */
33 typedef struct { long sec
; long usec
; } timeval_T
;
35 timeval_T
*timeval_from_milliseconds(timeval_T
*t
, milliseconds_T milliseconds
);
36 timeval_T
*timeval_from_seconds(timeval_T
*t
, long seconds
);
37 timeval_T
*timeval_from_double(timeval_T
*t
, double x
);
39 milliseconds_T
sec_to_ms(long sec
);
40 milliseconds_T
add_ms_to_ms(milliseconds_T a
, milliseconds_T b
);
41 milliseconds_T
mult_ms(milliseconds_T a
, long lb
);
43 milliseconds_T
timeval_to_milliseconds(timeval_T
*t
);
44 long timeval_to_seconds(timeval_T
*t
);
46 int timeval_is_positive(timeval_T
*t
);
47 void timeval_limit_to_zero_or_one(timeval_T
*t
);
48 timeval_T
*timeval_now(timeval_T
*t
);
49 timeval_T
*timeval_sub(timeval_T
*res
, timeval_T
*older
, timeval_T
*newer
);
50 timeval_T
*timeval_add(timeval_T
*res
, timeval_T
*base
, timeval_T
*t
);
51 int timeval_cmp(timeval_T
*t1
, timeval_T
*t2
);
52 timeval_T
*timeval_sub_interval(timeval_T
*t
, timeval_T
*interval
);
53 timeval_T
*timeval_add_interval(timeval_T
*t
, timeval_T
*interval
);
54 int timeval_div_off_t(off_t n
, timeval_T
*t
);
56 /** @relates timeval_T */
57 #define timeval_copy(dst, src) copy_struct(dst, src)