From: Christian Grothoff Date: Mon, 3 May 2010 20:39:50 +0000 (+0000) Subject: time subtract X-Git-Tag: initial-import-from-subversion-38251~21907 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=e098493e473fcdc4824e9ab05518ffe1460af1e6;p=oweals%2Fgnunet.git time subtract --- diff --git a/src/include/gnunet_time_lib.h b/src/include/gnunet_time_lib.h index b9c2d92f0..aa4e8d5db 100644 --- a/src/include/gnunet_time_lib.h +++ b/src/include/gnunet_time_lib.h @@ -314,6 +314,22 @@ struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_add (struct GNUNET_TIME_Relative duration); + +/** + * Subtract a given relative duration from the + * given start time. + * + * @param start some absolute time + * @param duration some relative time to subtract + * @return ZERO if start <= duration, or FOREVER if start time is FOREVER; start-duration otherwise + */ +struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_subtract (struct + GNUNET_TIME_Absolute + start, + struct + GNUNET_TIME_Relative + duration); + /** * Multiply relative time by a given factor. * diff --git a/src/util/time.c b/src/util/time.c index 6eccf4d9a..3d53e0af2 100644 --- a/src/util/time.c +++ b/src/util/time.c @@ -270,6 +270,33 @@ GNUNET_TIME_absolute_add (struct GNUNET_TIME_Absolute start, return ret; } + +/** + * Subtract a given relative duration from the + * given start time. + * + * @param start some absolute time + * @param duration some relative time to subtract + * @return ZERO if start <= duration, or FOREVER if start time is FOREVER; start-duration otherwise + */ +struct GNUNET_TIME_Absolute +GNUNET_TIME_absolute_subtract (struct + GNUNET_TIME_Absolute + start, + struct + GNUNET_TIME_Relative + duration) +{ + struct GNUNET_TIME_Absolute ret; + if (start.value <= duration.value) + return GNUNET_TIME_UNIT_ZERO_ABS; + if (start.value == GNUNET_TIME_UNIT_FOREVER_ABS.value) + return GNUNET_TIME_UNIT_FOREVER_ABS; + ret.value = start.value - duration.value; + return ret; +} + + /** * Multiply relative time by a given factor. *