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

Side by Side Diff: base/time.cc

Issue 10447110: WebKit will start using NaN to indicate null/invalid 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 | « no previous file | no next file » | 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
7 #include <math.h>
8 #if defined(OS_WIN)
9 #include <float.h>
10 #endif
11
6 #include "base/sys_string_conversions.h" 12 #include "base/sys_string_conversions.h"
7 #include "base/third_party/nspr/prtime.h" 13 #include "base/third_party/nspr/prtime.h"
8 14
9 #include "base/logging.h" 15 #include "base/logging.h"
10 16
11 namespace base { 17 namespace base {
12 18
19 namespace {
20 #if defined(OS_WIN)
21 inline bool isnan(double num) { return !!_isnan(num); }
22 #endif
23 }
24
13 // TimeDelta ------------------------------------------------------------------ 25 // TimeDelta ------------------------------------------------------------------
14 26
15 int TimeDelta::InDays() const { 27 int TimeDelta::InDays() const {
16 return static_cast<int>(delta_ / Time::kMicrosecondsPerDay); 28 return static_cast<int>(delta_ / Time::kMicrosecondsPerDay);
17 } 29 }
18 30
19 int TimeDelta::InHours() const { 31 int TimeDelta::InHours() const {
20 return static_cast<int>(delta_ / Time::kMicrosecondsPerHour); 32 return static_cast<int>(delta_ / Time::kMicrosecondsPerHour);
21 } 33 }
22 34
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 } 71 }
60 72
61 time_t Time::ToTimeT() const { 73 time_t Time::ToTimeT() const {
62 if (us_ == 0) 74 if (us_ == 0)
63 return 0; // Preserve 0 so we can tell it doesn't exist. 75 return 0; // Preserve 0 so we can tell it doesn't exist.
64 return (us_ - kTimeTToMicrosecondsOffset) / kMicrosecondsPerSecond; 76 return (us_ - kTimeTToMicrosecondsOffset) / kMicrosecondsPerSecond;
65 } 77 }
66 78
67 // static 79 // static
68 Time Time::FromDoubleT(double dt) { 80 Time Time::FromDoubleT(double dt) {
69 if (dt == 0) 81 if (dt == 0 || isnan(dt))
70 return Time(); // Preserve 0 so we can tell it doesn't exist. 82 return Time(); // Preserve 0 so we can tell it doesn't exist.
71 return Time(static_cast<int64>((dt * 83 return Time(static_cast<int64>((dt *
72 static_cast<double>(kMicrosecondsPerSecond)) + 84 static_cast<double>(kMicrosecondsPerSecond)) +
73 kTimeTToMicrosecondsOffset)); 85 kTimeTToMicrosecondsOffset));
74 } 86 }
75 87
76 double Time::ToDoubleT() const { 88 double Time::ToDoubleT() const {
77 if (us_ == 0) 89 if (us_ == 0)
78 return 0; // Preserve 0 so we can tell it doesn't exist. 90 return 0; // Preserve 0 so we can tell it doesn't exist.
79 return (static_cast<double>(us_ - kTimeTToMicrosecondsOffset) / 91 return (static_cast<double>(us_ - kTimeTToMicrosecondsOffset) /
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 return is_in_range(month, 1, 12) && 137 return is_in_range(month, 1, 12) &&
126 is_in_range(day_of_week, 0, 6) && 138 is_in_range(day_of_week, 0, 6) &&
127 is_in_range(day_of_month, 1, 31) && 139 is_in_range(day_of_month, 1, 31) &&
128 is_in_range(hour, 0, 23) && 140 is_in_range(hour, 0, 23) &&
129 is_in_range(minute, 0, 59) && 141 is_in_range(minute, 0, 59) &&
130 is_in_range(second, 0, 60) && 142 is_in_range(second, 0, 60) &&
131 is_in_range(millisecond, 0, 999); 143 is_in_range(millisecond, 0, 999);
132 } 144 }
133 145
134 } // namespace base 146 } // namespace base
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698