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

Side by Side Diff: base/time/time.cc

Issue 2655233003: Revert of base::Time should correctly handle -epoch time values from Javascript (Closed)
Patch Set: Created 3 years, 11 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
« no previous file with comments | « no previous file | base/time/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/time.h" 5 #include "base/time/time.h"
6 6
7 #include <cmath> 7 #include <cmath>
8 #include <ios> 8 #include <ios>
9 #include <limits> 9 #include <limits>
10 #include <ostream> 10 #include <ostream>
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 184
185 // static 185 // static
186 Time Time::FromJsTime(double ms_since_epoch) { 186 Time Time::FromJsTime(double ms_since_epoch) {
187 // The epoch is a valid time, so this constructor doesn't interpret 187 // The epoch is a valid time, so this constructor doesn't interpret
188 // 0 as the null time. 188 // 0 as the null time.
189 return Time(kTimeTToMicrosecondsOffset) + 189 return Time(kTimeTToMicrosecondsOffset) +
190 TimeDelta::FromMillisecondsD(ms_since_epoch); 190 TimeDelta::FromMillisecondsD(ms_since_epoch);
191 } 191 }
192 192
193 double Time::ToJsTime() const { 193 double Time::ToJsTime() const {
194 if (is_null()) {
195 // Preserve 0 so the invalid result doesn't depend on the platform.
196 return 0;
197 }
194 if (is_max()) { 198 if (is_max()) {
195 // Preserve max without offset to prevent overflow. 199 // Preserve max without offset to prevent overflow.
196 return std::numeric_limits<double>::infinity(); 200 return std::numeric_limits<double>::infinity();
197 } 201 }
198 return (static_cast<double>(us_ - kTimeTToMicrosecondsOffset) / 202 return (static_cast<double>(us_ - kTimeTToMicrosecondsOffset) /
199 kMicrosecondsPerMillisecond); 203 kMicrosecondsPerMillisecond);
200 } 204 }
201 205
202 Time Time::FromJavaTime(int64_t ms_since_epoch) { 206 Time Time::FromJavaTime(int64_t ms_since_epoch) {
203 return base::Time::UnixEpoch() + 207 return base::Time::UnixEpoch() +
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
338 return is_in_range(month, 1, 12) && 342 return is_in_range(month, 1, 12) &&
339 is_in_range(day_of_week, 0, 6) && 343 is_in_range(day_of_week, 0, 6) &&
340 is_in_range(day_of_month, 1, 31) && 344 is_in_range(day_of_month, 1, 31) &&
341 is_in_range(hour, 0, 23) && 345 is_in_range(hour, 0, 23) &&
342 is_in_range(minute, 0, 59) && 346 is_in_range(minute, 0, 59) &&
343 is_in_range(second, 0, 60) && 347 is_in_range(second, 0, 60) &&
344 is_in_range(millisecond, 0, 999); 348 is_in_range(millisecond, 0, 999);
345 } 349 }
346 350
347 } // namespace base 351 } // namespace base
OLDNEW
« no previous file with comments | « no previous file | base/time/time_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698