Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3102)

Unified Diff: base/time_posix.cc

Issue 10916089: Fixing Time::Max()'s behavior with Time::ToTimeT() and friends. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Windows. :( Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: base/time_posix.cc
diff --git a/base/time_posix.cc b/base/time_posix.cc
index c74cae5d15230377a01eabb7f5d85d05dbe58e73..c79781c3cf58d07c3d7ed4a6fc6094d59fae4fe2 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;

Powered by Google App Engine
This is Rietveld 408576698