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

Side by Side Diff: base/time.cc

Issue 10883061: Add 'base::Time::Max()' to explicitly refer to the end of time. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « base/time.h ('k') | base/time_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/time.h" 5 #include "base/time.h"
6 6
7 #include <math.h> 7 #include <math.h>
8 #if defined(OS_WIN) 8 #if defined(OS_WIN)
9 #include <float.h> 9 #include <float.h>
10 #endif 10 #endif
11 11
12 #include <limits>
13
12 #include "base/sys_string_conversions.h" 14 #include "base/sys_string_conversions.h"
13 #include "base/third_party/nspr/prtime.h" 15 #include "base/third_party/nspr/prtime.h"
14 16
15 #include "base/logging.h" 17 #include "base/logging.h"
16 18
17 namespace base { 19 namespace base {
18 20
19 namespace { 21 namespace {
20 #if defined(OS_WIN) 22 #if defined(OS_WIN)
21 inline bool isnan(double num) { return !!_isnan(num); } 23 inline bool isnan(double num) { return !!_isnan(num); }
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 Time::kMicrosecondsPerMillisecond; 59 Time::kMicrosecondsPerMillisecond;
58 } 60 }
59 61
60 int64 TimeDelta::InMicroseconds() const { 62 int64 TimeDelta::InMicroseconds() const {
61 return delta_; 63 return delta_;
62 } 64 }
63 65
64 // Time ----------------------------------------------------------------------- 66 // Time -----------------------------------------------------------------------
65 67
66 // static 68 // static
69 Time Time::Max() {
70 return Time(std::numeric_limits<int64>::max());
71 }
72
73 // static
67 Time Time::FromTimeT(time_t tt) { 74 Time Time::FromTimeT(time_t tt) {
68 if (tt == 0) 75 if (tt == 0)
69 return Time(); // Preserve 0 so we can tell it doesn't exist. 76 return Time(); // Preserve 0 so we can tell it doesn't exist.
70 return Time((tt * kMicrosecondsPerSecond) + kTimeTToMicrosecondsOffset); 77 return Time((tt * kMicrosecondsPerSecond) + kTimeTToMicrosecondsOffset);
71 } 78 }
72 79
73 time_t Time::ToTimeT() const { 80 time_t Time::ToTimeT() const {
74 if (us_ == 0) 81 if (us_ == 0)
75 return 0; // Preserve 0 so we can tell it doesn't exist. 82 return 0; // Preserve 0 so we can tell it doesn't exist.
76 return (us_ - kTimeTToMicrosecondsOffset) / kMicrosecondsPerSecond; 83 return (us_ - kTimeTToMicrosecondsOffset) / kMicrosecondsPerSecond;
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 return is_in_range(month, 1, 12) && 161 return is_in_range(month, 1, 12) &&
155 is_in_range(day_of_week, 0, 6) && 162 is_in_range(day_of_week, 0, 6) &&
156 is_in_range(day_of_month, 1, 31) && 163 is_in_range(day_of_month, 1, 31) &&
157 is_in_range(hour, 0, 23) && 164 is_in_range(hour, 0, 23) &&
158 is_in_range(minute, 0, 59) && 165 is_in_range(minute, 0, 59) &&
159 is_in_range(second, 0, 60) && 166 is_in_range(second, 0, 60) &&
160 is_in_range(millisecond, 0, 999); 167 is_in_range(millisecond, 0, 999);
161 } 168 }
162 169
163 } // namespace base 170 } // namespace base
OLDNEW
« no previous file with comments | « base/time.h ('k') | base/time_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698