Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 <limits> | 7 #include <limits> |
| 8 #include <ostream> | 8 #include <ostream> |
| 9 | 9 |
| 10 #include "base/float_util.h" | 10 #include "base/float_util.h" |
| 11 #include "base/lazy_instance.h" | |
| 11 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 //#include "base/memory/singleton.h" | |
|
jar (doing other things)
2013/10/30 20:00:12
nit: delete... not needed.
pwestin
2013/10/30 23:14:30
Done.
| |
| 12 #include "base/third_party/nspr/prtime.h" | 14 #include "base/third_party/nspr/prtime.h" |
| 13 #include "base/third_party/nspr/prtypes.h" | 15 #include "base/third_party/nspr/prtypes.h" |
| 14 | 16 |
| 15 namespace base { | 17 namespace base { |
| 16 | 18 |
| 17 // TimeDelta ------------------------------------------------------------------ | 19 // TimeDelta ------------------------------------------------------------------ |
| 18 | 20 |
| 19 int TimeDelta::InDays() const { | 21 int TimeDelta::InDays() const { |
| 20 return static_cast<int>(delta_ / Time::kMicrosecondsPerDay); | 22 return static_cast<int>(delta_ / Time::kMicrosecondsPerDay); |
| 21 } | 23 } |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 182 is_local ? PR_FALSE : PR_TRUE, | 184 is_local ? PR_FALSE : PR_TRUE, |
| 183 &result_time); | 185 &result_time); |
| 184 if (PR_SUCCESS != result) | 186 if (PR_SUCCESS != result) |
| 185 return false; | 187 return false; |
| 186 | 188 |
| 187 result_time += kTimeTToMicrosecondsOffset; | 189 result_time += kTimeTToMicrosecondsOffset; |
| 188 *parsed_time = Time(result_time); | 190 *parsed_time = Time(result_time); |
| 189 return true; | 191 return true; |
| 190 } | 192 } |
| 191 | 193 |
| 194 // Local helper class to hold the conversion from Time to TickTime at the | |
| 195 // time of the Unix epoch. | |
| 196 class UnixEpochSingleton { | |
| 197 public: | |
| 198 UnixEpochSingleton() | |
| 199 : unix_epoch_(TimeTicks::Now() - (Time::Now() - Time::UnixEpoch())) {} | |
| 200 | |
| 201 TimeTicks unix_epoch() const { return unix_epoch_; } | |
| 202 | |
| 203 private: | |
| 204 const TimeTicks unix_epoch_; | |
| 205 }; | |
|
jar (doing other things)
2013/10/30 20:00:12
nit: DISALLOW_COPY_AND_ASSIGN
pwestin
2013/10/30 23:14:30
Done.
| |
| 206 | |
| 207 static LazyInstance<UnixEpochSingleton>::Leaky | |
| 208 leaky_unix_epoch_singleton_instance = LAZY_INSTANCE_INITIALIZER; | |
| 209 | |
| 210 // Static | |
| 211 TimeTicks TimeTicks::UnixEpoch() { | |
| 212 return leaky_unix_epoch_singleton_instance.Get().unix_epoch(); | |
| 213 } | |
| 214 | |
| 192 // Time::Exploded ------------------------------------------------------------- | 215 // Time::Exploded ------------------------------------------------------------- |
| 193 | 216 |
| 194 inline bool is_in_range(int value, int lo, int hi) { | 217 inline bool is_in_range(int value, int lo, int hi) { |
| 195 return lo <= value && value <= hi; | 218 return lo <= value && value <= hi; |
| 196 } | 219 } |
| 197 | 220 |
| 198 bool Time::Exploded::HasValidValues() const { | 221 bool Time::Exploded::HasValidValues() const { |
| 199 return is_in_range(month, 1, 12) && | 222 return is_in_range(month, 1, 12) && |
| 200 is_in_range(day_of_week, 0, 6) && | 223 is_in_range(day_of_week, 0, 6) && |
| 201 is_in_range(day_of_month, 1, 31) && | 224 is_in_range(day_of_month, 1, 31) && |
| 202 is_in_range(hour, 0, 23) && | 225 is_in_range(hour, 0, 23) && |
| 203 is_in_range(minute, 0, 59) && | 226 is_in_range(minute, 0, 59) && |
| 204 is_in_range(second, 0, 60) && | 227 is_in_range(second, 0, 60) && |
| 205 is_in_range(millisecond, 0, 999); | 228 is_in_range(millisecond, 0, 999); |
| 206 } | 229 } |
| 207 | 230 |
| 208 } // namespace base | 231 } // namespace base |
| OLD | NEW |