summaryrefslogtreecommitdiffstats
path: root/base
diff options
context:
space:
mode:
Diffstat (limited to 'base')
-rw-r--r--base/time.cc9
-rw-r--r--base/time.h6
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;