diff options
author | mkwst@chromium.org <mkwst@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-09-08 17:50:07 +0000 |
---|---|---|
committer | mkwst@chromium.org <mkwst@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-09-08 17:50:07 +0000 |
commit | a9e5f04481565af0a3c8dbe770b14899f24b68f7 (patch) | |
tree | 4565198c5cdff1435acd19f5efc903eb306ee061 /base/time_posix.cc | |
parent | 4a6d53c71fb914da3dd9e15cdc72b385b91701ec (diff) | |
download | chromium_src-a9e5f04481565af0a3c8dbe770b14899f24b68f7.zip chromium_src-a9e5f04481565af0a3c8dbe770b14899f24b68f7.tar.gz chromium_src-a9e5f04481565af0a3c8dbe770b14899f24b68f7.tar.bz2 |
Fixing Time::Max()'s behavior with Time::ToTimeT() and friends.
It looks like the math that's done to convert epoch times between platforms is
giving incorrect results when confronted with a "max" time. This CL adjusts the
various conversion methods to persist maxness in the same way they currently
persist zeroness.
BUG=146328
Review URL: https://chromiumcodereview.appspot.com/10916089
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@155591 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/time_posix.cc')
-rw-r--r-- | base/time_posix.cc | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/base/time_posix.cc b/base/time_posix.cc index c74cae5..c79781c 100644 --- a/base/time_posix.cc +++ b/base/time_posix.cc @@ -266,6 +266,11 @@ TimeTicks TimeTicks::NowFromSystemTraceTime() { Time Time::FromTimeVal(struct timeval t) { DCHECK_LT(t.tv_usec, static_cast<int>(Time::kMicrosecondsPerSecond)); DCHECK_GE(t.tv_usec, 0); + if (t.tv_usec == 0 && t.tv_sec == 0) + return Time(); + if (t.tv_usec == static_cast<suseconds_t>(Time::kMicrosecondsPerSecond) - 1 && + t.tv_sec == std::numeric_limits<time_t>::max()) + return Max(); return Time( (static_cast<int64>(t.tv_sec) * Time::kMicrosecondsPerSecond) + t.tv_usec + @@ -274,6 +279,16 @@ Time Time::FromTimeVal(struct timeval t) { struct timeval Time::ToTimeVal() const { struct timeval result; + if (is_null()) { + result.tv_sec = 0; + result.tv_usec = 0; + return result; + } + if (is_max()) { + result.tv_sec = std::numeric_limits<time_t>::max(); + result.tv_usec = static_cast<suseconds_t>(Time::kMicrosecondsPerSecond) - 1; + return result; + } int64 us = us_ - kTimeTToMicrosecondsOffset; result.tv_sec = us / Time::kMicrosecondsPerSecond; result.tv_usec = us % Time::kMicrosecondsPerSecond; |