time subtract
authorChristian Grothoff <christian@grothoff.org>
Mon, 3 May 2010 20:39:50 +0000 (20:39 +0000)
committerChristian Grothoff <christian@grothoff.org>
Mon, 3 May 2010 20:39:50 +0000 (20:39 +0000)
src/include/gnunet_time_lib.h
src/util/time.c

index b9c2d92f042192dcf2c01c98768381371c825a63..aa4e8d5db745dfade311145b5b596586fea5a645 100644 (file)
@@ -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.
  *
index 6eccf4d9ab995710d4eca7a88adbb1a32a8330b0..3d53e0af2f8a36809610eb484db09380af3c3f95 100644 (file)
@@ -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.
  *