Add time_until() and time_since() utility functions
Adding these in preparation for converting server->connect_time from time_t to struct timeval. Also converts three existing open-coded versions over to the new functions.
This commit is contained in:
@@ -1746,6 +1746,24 @@ double BX_time_diff (struct timeval one, struct timeval two)
|
||||
return (double)td.tv_sec + ((double)td.tv_usec / 1000000.0);
|
||||
}
|
||||
|
||||
/* Calculate time elapsed since a time in the past. */
|
||||
double time_since(const struct timeval *tv_from)
|
||||
{
|
||||
struct timeval tv_now;
|
||||
|
||||
get_time(&tv_now);
|
||||
return BX_time_diff(*tv_from, tv_now);
|
||||
}
|
||||
|
||||
/* Calculate time from now until a time in the future. */
|
||||
double time_until(const struct timeval *tv_to)
|
||||
{
|
||||
struct timeval tv_now;
|
||||
|
||||
get_time(&tv_now);
|
||||
return BX_time_diff(tv_now, *tv_to);
|
||||
}
|
||||
|
||||
int BX_time_to_next_minute (void)
|
||||
{
|
||||
time_t now = time(NULL);
|
||||
|
||||
Reference in New Issue
Block a user