update_engine: Make utils::FormatTimeDelta() work with negative values.

BUG=chromium:401862
TEST=New unit test + unit tests pass.

Change-Id: I89b7ec72c11b792d4353eb6b36b23eac4f82107d
Reviewed-on: https://chromium-review.googlesource.com/212878
Reviewed-by: Mike Frysinger <vapier@chromium.org>
Reviewed-by: Alex Deymo <deymo@chromium.org>
Commit-Queue: David Zeuthen <zeuthen@chromium.org>
Tested-by: David Zeuthen <zeuthen@chromium.org>
diff --git a/utils.cc b/utils.cc
index 2c17be8..37d1c9a 100644
--- a/utils.cc
+++ b/utils.cc
@@ -843,6 +843,14 @@
 }
 
 string FormatTimeDelta(TimeDelta delta) {
+  string str;
+
+  // Handle negative durations by prefixing with a minus.
+  if (delta.ToInternalValue() < 0) {
+    delta *= -1;
+    str = "-";
+  }
+
   // Canonicalize into days, hours, minutes, seconds and microseconds.
   unsigned days = delta.InDays();
   delta -= TimeDelta::FromDays(days);
@@ -854,8 +862,6 @@
   delta -= TimeDelta::FromSeconds(secs);
   unsigned usecs = delta.InMicroseconds();
 
-  // Construct and return string.
-  string str;
   if (days)
     base::StringAppendF(&str, "%ud", days);
   if (days || hours)