diff options
author | jianli@chromium.org <jianli@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-09-09 17:17:55 +0000 |
---|---|---|
committer | jianli@chromium.org <jianli@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-09-09 17:17:55 +0000 |
commit | c925ad166b4825c6412a318092a664da58b5f365 (patch) | |
tree | ea292d1cdcb394ef50c93f57b20cf7f35a1ffac0 /base | |
parent | feed0677b1f7f719498d3b08f0dab523a4c095e7 (diff) | |
download | chromium_src-c925ad166b4825c6412a318092a664da58b5f365.zip chromium_src-c925ad166b4825c6412a318092a664da58b5f365.tar.gz chromium_src-c925ad166b4825c6412a318092a664da58b5f365.tar.bz2 |
Fix Time::FromDoubleT so that it will return null time when 0 is passed.
This is the rework of this issue before previous submit is reverted. We need to
fix the usage of Time::FromDoubleT(0) in extension history API.
BUG=none
TEST=non
Review URL: http://codereview.chromium.org/3295001
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@58953 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r-- | base/time.cc | 9 | ||||
-rw-r--r-- | base/time.h | 6 |
2 files changed, 15 insertions, 0 deletions
diff --git a/base/time.cc b/base/time.cc index 383f939..766f599 100644 --- a/base/time.cc +++ b/base/time.cc @@ -66,6 +66,8 @@ time_t Time::ToTimeT() const { // static Time Time::FromDoubleT(double dt) { + if (dt == 0) + return Time(); // Preserve 0 so we can tell it doesn't exist. return Time(static_cast<int64>((dt * static_cast<double>(kMicrosecondsPerSecond)) + kTimeTToMicrosecondsOffset)); @@ -78,6 +80,13 @@ double Time::ToDoubleT() const { static_cast<double>(kMicrosecondsPerSecond)); } +// static +Time Time::UnixEpoch() { + Time time; + time.us_ = kTimeTToMicrosecondsOffset; + return time; +} + Time Time::LocalMidnight() const { Exploded exploded; LocalExplode(&exploded); diff --git a/base/time.h b/base/time.h index 0f5eb5d..0ed7957 100644 --- a/base/time.h +++ b/base/time.h @@ -230,6 +230,9 @@ class Time { return us_ == 0; } + // Returns the time for epoch in Unix-like system (Jan 1, 1970). + static Time UnixEpoch(); + // Returns the current time. Watch out, the system might adjust its clock // in which case time will actually go backwards. We don't guarantee that // times are increasing, or that two calls to Now() won't be the same. @@ -249,6 +252,9 @@ class Time { // Converts time to/from a double which is the number of seconds since epoch // (Jan 1, 1970). Webkit uses this format to represent time. + // Because WebKit initializes double time value to 0 to indicate "not + // initialized", we map it to empty Time object that also means "not + // initialized". static Time FromDoubleT(double dt); double ToDoubleT() const; |