 Chromium Code Reviews
 Chromium Code Reviews Issue 10916089:
  Fixing Time::Max()'s behavior with Time::ToTimeT() and friends.  (Closed) 
  Base URL: svn://svn.chromium.org/chrome/trunk/src
    
  
    Issue 10916089:
  Fixing Time::Max()'s behavior with Time::ToTimeT() and friends.  (Closed) 
  Base URL: svn://svn.chromium.org/chrome/trunk/src| Index: base/time_posix.cc | 
| diff --git a/base/time_posix.cc b/base/time_posix.cc | 
| index c74cae5d15230377a01eabb7f5d85d05dbe58e73..c6c416a34f3495eaf50d221a5dd6184f21f2b43e 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<int>(Time::kMicrosecondsPerSecond) - 1 && | 
| 
Mark Mentovai
2012/09/05 15:27:53
For correctness, you should use the type of the tv
 | 
| + t.tv_sec == std::numeric_limits<int64>::max()) | 
| 
Mark Mentovai
2012/09/05 15:27:53
And the type of the tv_sec field, time_t, here.
 | 
| + return Max(); | 
| return Time( | 
| (static_cast<int64>(t.tv_sec) * Time::kMicrosecondsPerSecond) + | 
| t.tv_usec + | 
| @@ -274,6 +279,15 @@ 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<int64>::max(); | 
| 
Mark Mentovai
2012/09/05 15:27:53
Again on these two lines.
 | 
| + result.tv_usec = static_cast<int>(Time::kMicrosecondsPerSecond) - 1; | 
| + } | 
| int64 us = us_ - kTimeTToMicrosecondsOffset; | 
| result.tv_sec = us / Time::kMicrosecondsPerSecond; | 
| result.tv_usec = us % Time::kMicrosecondsPerSecond; |