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

Side by Side Diff: base/time.cc

Issue 10536061: Add Javascript time methods to base::Time. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 6 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 #include "base/sys_string_conversions.h" 6 #include "base/sys_string_conversions.h"
7 #include "base/third_party/nspr/prtime.h" 7 #include "base/third_party/nspr/prtime.h"
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 10
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 } 74 }
75 75
76 double Time::ToDoubleT() const { 76 double Time::ToDoubleT() const {
77 if (us_ == 0) 77 if (us_ == 0)
78 return 0; // Preserve 0 so we can tell it doesn't exist. 78 return 0; // Preserve 0 so we can tell it doesn't exist.
79 return (static_cast<double>(us_ - kTimeTToMicrosecondsOffset) / 79 return (static_cast<double>(us_ - kTimeTToMicrosecondsOffset) /
80 static_cast<double>(kMicrosecondsPerSecond)); 80 static_cast<double>(kMicrosecondsPerSecond));
81 } 81 }
82 82
83 // static 83 // static
84 Time Time::FromJsTime(double ms_since_epoch) {
85 // The epoch is a valid time, so this constructor doesn't interpret
86 // 0 as the null time.
87 return Time(static_cast<int64>(ms_since_epoch * kMicrosecondsPerMillisecond) +
88 kTimeTToMicrosecondsOffset);
89 }
90
91 double Time::ToJsTime() const {
92 if (us_ == 0) {
Jeffrey Yasskin 2012/06/08 19:20:16 It may actually make sense to CHECK(!is_null()) he
93 // Preserve 0 so the invalid result doesn't depend on the platform.
94 return 0;
95 }
96 return (static_cast<double>(us_ - kTimeTToMicrosecondsOffset) /
97 kMicrosecondsPerMillisecond);
98 }
99
100 // static
84 Time Time::UnixEpoch() { 101 Time Time::UnixEpoch() {
85 Time time; 102 Time time;
86 time.us_ = kTimeTToMicrosecondsOffset; 103 time.us_ = kTimeTToMicrosecondsOffset;
87 return time; 104 return time;
88 } 105 }
89 106
90 Time Time::LocalMidnight() const { 107 Time Time::LocalMidnight() const {
91 Exploded exploded; 108 Exploded exploded;
92 LocalExplode(&exploded); 109 LocalExplode(&exploded);
93 exploded.hour = 0; 110 exploded.hour = 0;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 return is_in_range(month, 1, 12) && 142 return is_in_range(month, 1, 12) &&
126 is_in_range(day_of_week, 0, 6) && 143 is_in_range(day_of_week, 0, 6) &&
127 is_in_range(day_of_month, 1, 31) && 144 is_in_range(day_of_month, 1, 31) &&
128 is_in_range(hour, 0, 23) && 145 is_in_range(hour, 0, 23) &&
129 is_in_range(minute, 0, 59) && 146 is_in_range(minute, 0, 59) &&
130 is_in_range(second, 0, 60) && 147 is_in_range(second, 0, 60) &&
131 is_in_range(millisecond, 0, 999); 148 is_in_range(millisecond, 0, 999);
132 } 149 }
133 150
134 } // namespace base 151 } // 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