OLD | NEW |
---|---|
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 Loading... | |
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 Loading... | |
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 |
OLD | NEW |