diff --git a/include/ircaux.h b/include/ircaux.h index 98282bd..af363ca 100644 --- a/include/ircaux.h +++ b/include/ircaux.h @@ -84,6 +84,8 @@ int lw_strcmp (comp_func *, char *, char *); int open_to (char *, int, off_t); struct timeval BX_get_time (struct timeval *); double BX_time_diff (struct timeval, struct timeval); +double time_since(const struct timeval *tv_from); +double time_until(const struct timeval *tv_to); char * BX_plural (int); int BX_time_to_next_minute (void); char * BX_remove_trailing_spaces (char *); diff --git a/source/commands.c b/source/commands.c index e24e3b5..fe11f39 100644 --- a/source/commands.c +++ b/source/commands.c @@ -5531,7 +5531,7 @@ struct timeval start; * with the arguments. */ add_timer(0, empty_string, milliseconds, 1, (int (*)(void *, char *))comment, NULL, NULL, get_current_winref(), "pause"); - while (BX_time_diff(get_time(NULL), start) > 0) + while (time_until(&start) > 0) io("e_pause"); } diff --git a/source/dcc.c b/source/dcc.c index f390cfd..459e0ec 100644 --- a/source/dcc.c +++ b/source/dcc.c @@ -1617,7 +1617,7 @@ char lame_type[30]; strcpy(lame_type, "T"); strcat(lame_type, dcc_types[type]->name); - xtime = BX_time_diff(n->starttime, get_time(NULL)); + xtime = time_since(&n->starttime); xfer = (double)(n->bytes_sent ? n->bytes_sent : n->bytes_read); if (xfer == 0.0) @@ -2884,7 +2884,7 @@ DCC_int *n; return; dcc_bytes_in += n->bytes_read; dcc_bytes_out += n->bytes_sent; - xtime = BX_time_diff(n->starttime, get_time(NULL)); + xtime = time_since(&n->starttime); if (xtime <= 0) xtime = 1; diff --git a/source/ircaux.c b/source/ircaux.c index 3de933d..cab9395 100644 --- a/source/ircaux.c +++ b/source/ircaux.c @@ -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);