Index: base/time/time_logging.cc |
diff --git a/base/time/time_logging.cc b/base/time/time_logging.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..7574eabc3709b29c991edcd569f970d3a0884def |
--- /dev/null |
+++ b/base/time/time_logging.cc |
@@ -0,0 +1,42 @@ |
+// Copyright 2014 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+// Resist the urge to make the output of these fancy. They are just for |
+// debugging. |
+ |
+#include "base/time/time_logging.h" |
+ |
+#include <iostream> |
+ |
+#include "base/strings/stringprintf.h" |
+#include "base/time/time.h" |
+ |
+namespace base { |
+ |
+std::ostream& operator<<(std::ostream& os, const TimeDelta& time_delta) { |
+ return os << time_delta.InSecondsF() << "s"; |
+} |
+ |
+std::ostream& operator<<(std::ostream& os, const Time& time) { |
+ Time::Exploded e; |
mmenke
2014/10/21 14:20:09
nit: Google style guide strong discourages using
Adam Rice
2014/10/23 01:13:02
Done.
|
+ time.UTCExplode(&e); |
+ // Use StringPrintf because iostreams formatting is painful. |
+ return os << StringPrintf("%04d-%02d-%02d %02d:%02d:%02d.%03d UTC", |
+ e.year, |
+ e.month, |
+ e.day_of_month, |
+ e.hour, |
+ e.minute, |
+ e.second, |
+ e.millisecond); |
+} |
+ |
+std::ostream& operator<<(std::ostream& os, const TimeTicks& time_ticks) { |
+ // This function formats a TimeTicks object as if it was a Time object. |
+ const Time as_time = |
+ Time::UnixEpoch() + (time_ticks - TimeTicks::UnixEpoch()); |
+ return os << as_time; |
+} |
+ |
+} // namespace base |