Chromium Code Reviews| Index: base/time/time.cc |
| diff --git a/base/time/time.cc b/base/time/time.cc |
| index f7313565a3e80542599fc597642b9594a4f426db..18155e89cc3e35b34c93037fe6ea72e3312b3d4b 100644 |
| --- a/base/time/time.cc |
| +++ b/base/time/time.cc |
| @@ -4,12 +4,15 @@ |
| #include "base/time/time.h" |
| +#include <ios> |
| #include <limits> |
| #include <ostream> |
| +#include <sstream> |
| #include "base/float_util.h" |
| #include "base/lazy_instance.h" |
| #include "base/logging.h" |
| +#include "base/strings/stringprintf.h" |
| #include "base/third_party/nspr/prtime.h" |
| namespace base { |
| @@ -94,6 +97,10 @@ int64 TimeDelta::InMicroseconds() const { |
| return delta_; |
| } |
| +std::ostream& operator<<(std::ostream& os, TimeDelta time_delta) { |
| + return os << time_delta.InSecondsF() << "s"; |
| +} |
| + |
| // Time ----------------------------------------------------------------------- |
| // static |
| @@ -230,6 +237,20 @@ bool Time::FromStringInternal(const char* time_string, |
| return true; |
| } |
| +std::ostream& operator<<(std::ostream& os, Time time) { |
| + Time::Exploded exploded; |
| + time.UTCExplode(&exploded); |
| + // Use StringPrintf because iostreams formatting is painful. |
| + return os << StringPrintf("%04d-%02d-%02d %02d:%02d:%02d.%03d UTC", |
| + exploded.year, |
| + exploded.month, |
| + exploded.day_of_month, |
| + exploded.hour, |
| + exploded.minute, |
| + exploded.second, |
| + exploded.millisecond); |
| +} |
| + |
| // Local helper class to hold the conversion from Time to TickTime at the |
| // time of the Unix epoch. |
| class UnixEpochSingleton { |
| @@ -253,6 +274,13 @@ TimeTicks TimeTicks::UnixEpoch() { |
| return leaky_unix_epoch_singleton_instance.Get().unix_epoch(); |
| } |
| +std::ostream& operator<<(std::ostream& os, TimeTicks time_ticks) { |
| + // This function formats a TimeTicks object as if it was a Time object. |
|
rvargas (doing something else)
2014/10/23 02:36:38
Shouldn't we log TimeTicks as a TimeDelta instead?
Adam Rice
2014/10/23 03:42:02
TimeDeltas are normally logged to 4 digits of prec
rvargas (doing something else)
2014/10/23 19:30:43
But TimeTicks expressed as a random date doesn't s
Adam Rice
2014/10/24 04:05:39
In the "rounding error" and "monotonic clock faile
rvargas (doing something else)
2014/10/24 23:24:18
The second one sounds like a TimeTicks unit test n
Adam Rice
2014/10/28 05:43:12
Okay, I changed it to "bogo-microseconds".
I see
|
| + const Time as_time = |
| + Time::UnixEpoch() + (time_ticks - TimeTicks::UnixEpoch()); |
| + return os << as_time; |
| +} |
| + |
| // Time::Exploded ------------------------------------------------------------- |
| inline bool is_in_range(int value, int lo, int hi) { |