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:
Kevin Easton
2015-05-13 21:50:30 +10:00
parent 0f8280ed51
commit 4ee6c6295b
4 changed files with 23 additions and 3 deletions

View File

@@ -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);