Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 // Time represents an absolute point in time, internally represented as | 5 // Time represents an absolute point in time, internally represented as |
| 6 // microseconds (s/1,000,000) since a platform-dependent epoch. Each | 6 // microseconds (s/1,000,000) since a platform-dependent epoch. Each |
| 7 // platform's epoch, along with other system-dependent clock interface | 7 // platform's epoch, along with other system-dependent clock interface |
| 8 // routines, is defined in time_PLATFORM.cc. | 8 // routines, is defined in time_PLATFORM.cc. |
| 9 // | 9 // |
| 10 // TimeDelta represents a duration of time, internally represented in | 10 // TimeDelta represents a duration of time, internally represented in |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 38 // For struct timeval. | 38 // For struct timeval. |
| 39 #include <sys/time.h> | 39 #include <sys/time.h> |
| 40 #endif | 40 #endif |
| 41 | 41 |
| 42 #if defined(OS_WIN) | 42 #if defined(OS_WIN) |
| 43 // For FILETIME in FromFileTime, until it moves to a new converter class. | 43 // For FILETIME in FromFileTime, until it moves to a new converter class. |
| 44 // See TODO(iyengar) below. | 44 // See TODO(iyengar) below. |
| 45 #include <windows.h> | 45 #include <windows.h> |
| 46 #endif | 46 #endif |
| 47 | 47 |
| 48 #include <limits> | |
| 49 | |
| 48 namespace base { | 50 namespace base { |
| 49 | 51 |
| 50 class Time; | 52 class Time; |
| 51 class TimeTicks; | 53 class TimeTicks; |
| 52 | 54 |
| 53 // TimeDelta ------------------------------------------------------------------ | 55 // TimeDelta ------------------------------------------------------------------ |
| 54 | 56 |
| 55 class BASE_EXPORT TimeDelta { | 57 class BASE_EXPORT TimeDelta { |
| 56 public: | 58 public: |
| 57 TimeDelta() : delta_(0) { | 59 TimeDelta() : delta_(0) { |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 239 | 241 |
| 240 // Contains the NULL time. Use Time::Now() to get the current time. | 242 // Contains the NULL time. Use Time::Now() to get the current time. |
| 241 explicit Time() : us_(0) { | 243 explicit Time() : us_(0) { |
| 242 } | 244 } |
| 243 | 245 |
| 244 // Returns true if the time object has not been initialized. | 246 // Returns true if the time object has not been initialized. |
| 245 bool is_null() const { | 247 bool is_null() const { |
| 246 return us_ == 0; | 248 return us_ == 0; |
| 247 } | 249 } |
| 248 | 250 |
| 251 // Returns true if the time object is the maximum time. | |
| 252 bool is_max() const { | |
| 253 return us_ == std::numeric_limits<int64>::max(); | |
| 254 } | |
| 255 | |
| 249 // Returns the time for epoch in Unix-like system (Jan 1, 1970). | 256 // Returns the time for epoch in Unix-like system (Jan 1, 1970). |
| 250 static Time UnixEpoch(); | 257 static Time UnixEpoch(); |
| 251 | 258 |
| 252 // Returns the current time. Watch out, the system might adjust its clock | 259 // Returns the current time. Watch out, the system might adjust its clock |
| 253 // in which case time will actually go backwards. We don't guarantee that | 260 // in which case time will actually go backwards. We don't guarantee that |
| 254 // times are increasing, or that two calls to Now() won't be the same. | 261 // times are increasing, or that two calls to Now() won't be the same. |
| 255 static Time Now(); | 262 static Time Now(); |
| 256 | 263 |
| 257 // Returns the maximum time, which should be greater than any reasonable time | 264 // Returns the maximum time, which should be greater than any reasonable time |
| 258 // with which we might compare it. | 265 // with which we might compare it. |
| 259 static Time Max(); | 266 static Time Max(); |
| 260 | 267 |
| 261 // Returns the current time. Same as Now() except that this function always | 268 // Returns the current time. Same as Now() except that this function always |
| 262 // uses system time so that there are no discrepancies between the returned | 269 // uses system time so that there are no discrepancies between the returned |
| 263 // time and system time even on virtual environments including our test bot. | 270 // time and system time even on virtual environments including our test bot. |
| 264 // For timing sensitive unittests, this function should be used. | 271 // For timing sensitive unittests, this function should be used. |
| 265 static Time NowFromSystemTime(); | 272 static Time NowFromSystemTime(); |
| 266 | 273 |
| 267 // Converts to/from time_t in UTC and a Time class. | 274 // Converts to/from time_t in UTC and a Time class. |
| 268 // TODO(brettw) this should be removed once everybody starts using the |Time| | 275 // TODO(brettw) this should be removed once everybody starts using the |Time| |
| 269 // class. | 276 // class. |
| 270 static Time FromTimeT(time_t tt); | 277 static Time FromTimeT(time_t tt); |
|
Mark Mentovai
2012/09/04 13:23:14
Max preservation for time_t, WebKit double, and JS
| |
| 271 time_t ToTimeT() const; | 278 time_t ToTimeT() const; |
| 272 | 279 |
| 273 // Converts time to/from a double which is the number of seconds since epoch | 280 // Converts time to/from a double which is the number of seconds since epoch |
| 274 // (Jan 1, 1970). Webkit uses this format to represent time. | 281 // (Jan 1, 1970). Webkit uses this format to represent time. |
| 275 // Because WebKit initializes double time value to 0 to indicate "not | 282 // Because WebKit initializes double time value to 0 to indicate "not |
| 276 // initialized", we map it to empty Time object that also means "not | 283 // initialized", we map it to empty Time object that also means "not |
| 277 // initialized". | 284 // initialized". |
| 278 static Time FromDoubleT(double dt); | 285 static Time FromDoubleT(double dt); |
| 279 double ToDoubleT() const; | 286 double ToDoubleT() const; |
| 280 | 287 |
| 281 // Converts to/from the Javascript convention for times, a number of | 288 // Converts to/from the Javascript convention for times, a number of |
| 282 // milliseconds since the epoch: | 289 // milliseconds since the epoch: |
| 283 // https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Date/g etTime. | 290 // https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Date/g etTime. |
| 284 static Time FromJsTime(double ms_since_epoch); | 291 static Time FromJsTime(double ms_since_epoch); |
| 285 double ToJsTime() const; | 292 double ToJsTime() const; |
| 286 | 293 |
| 287 #if defined(OS_POSIX) | 294 #if defined(OS_POSIX) |
| 288 static Time FromTimeVal(struct timeval t); | 295 static Time FromTimeVal(struct timeval t); |
|
Mark Mentovai
2012/09/04 13:23:14
no max preservation for this, or CFAbsoluteTime, o
| |
| 289 struct timeval ToTimeVal() const; | 296 struct timeval ToTimeVal() const; |
| 290 #endif | 297 #endif |
| 291 | 298 |
| 292 #if defined(OS_MACOSX) | 299 #if defined(OS_MACOSX) |
| 293 static Time FromCFAbsoluteTime(CFAbsoluteTime t); | 300 static Time FromCFAbsoluteTime(CFAbsoluteTime t); |
| 294 CFAbsoluteTime ToCFAbsoluteTime() const; | 301 CFAbsoluteTime ToCFAbsoluteTime() const; |
| 295 #endif | 302 #endif |
| 296 | 303 |
| 297 #if defined(OS_WIN) | 304 #if defined(OS_WIN) |
| 298 static Time FromFileTime(FILETIME ft); | 305 static Time FromFileTime(FILETIME ft); |
| (...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 608 #endif | 615 #endif |
| 609 }; | 616 }; |
| 610 | 617 |
| 611 inline TimeTicks TimeDelta::operator+(TimeTicks t) const { | 618 inline TimeTicks TimeDelta::operator+(TimeTicks t) const { |
| 612 return TimeTicks(t.ticks_ + delta_); | 619 return TimeTicks(t.ticks_ + delta_); |
| 613 } | 620 } |
| 614 | 621 |
| 615 } // namespace base | 622 } // namespace base |
| 616 | 623 |
| 617 #endif // BASE_TIME_H_ | 624 #endif // BASE_TIME_H_ |
| OLD | NEW |