OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/string_util.h" | 6 #include "base/string_util.h" |
7 #include "base/sys_string_conversions.h" | 7 #include "base/sys_string_conversions.h" |
8 #include "base/third_party/nspr/prtime.h" | 8 #include "base/third_party/nspr/prtime.h" |
9 | 9 |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 | 11 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 int64 TimeDelta::InMicroseconds() const { | 44 int64 TimeDelta::InMicroseconds() const { |
45 return delta_; | 45 return delta_; |
46 } | 46 } |
47 | 47 |
48 // Time ----------------------------------------------------------------------- | 48 // Time ----------------------------------------------------------------------- |
49 | 49 |
50 // static | 50 // static |
51 Time Time::FromTimeT(time_t tt) { | 51 Time Time::FromTimeT(time_t tt) { |
52 if (tt == 0) | 52 if (tt == 0) |
53 return Time(); // Preserve 0 so we can tell it doesn't exist. | 53 return Time(); // Preserve 0 so we can tell it doesn't exist. |
54 return (tt * kMicrosecondsPerSecond) + kTimeTToMicrosecondsOffset; | 54 return Time((tt * kMicrosecondsPerSecond) + kTimeTToMicrosecondsOffset); |
55 } | 55 } |
56 | 56 |
57 time_t Time::ToTimeT() const { | 57 time_t Time::ToTimeT() const { |
58 if (us_ == 0) | 58 if (us_ == 0) |
59 return 0; // Preserve 0 so we can tell it doesn't exist. | 59 return 0; // Preserve 0 so we can tell it doesn't exist. |
60 return (us_ - kTimeTToMicrosecondsOffset) / kMicrosecondsPerSecond; | 60 return (us_ - kTimeTToMicrosecondsOffset) / kMicrosecondsPerSecond; |
61 } | 61 } |
62 | 62 |
63 // static | 63 // static |
64 Time Time::FromDoubleT(double dt) { | 64 Time Time::FromDoubleT(double dt) { |
65 return (dt * static_cast<double>(kMicrosecondsPerSecond)) + | 65 return Time(static_cast<int64>((dt * |
66 kTimeTToMicrosecondsOffset; | 66 static_cast<double>(kMicrosecondsPerSecond)) + |
| 67 kTimeTToMicrosecondsOffset)); |
67 } | 68 } |
68 | 69 |
69 double Time::ToDoubleT() const { | 70 double Time::ToDoubleT() const { |
70 if (us_ == 0) | 71 if (us_ == 0) |
71 return 0; // Preserve 0 so we can tell it doesn't exist. | 72 return 0; // Preserve 0 so we can tell it doesn't exist. |
72 return (static_cast<double>(us_ - kTimeTToMicrosecondsOffset) / | 73 return (static_cast<double>(us_ - kTimeTToMicrosecondsOffset) / |
73 static_cast<double>(kMicrosecondsPerSecond)); | 74 static_cast<double>(kMicrosecondsPerSecond)); |
74 } | 75 } |
75 | 76 |
76 Time Time::LocalMidnight() const { | 77 Time Time::LocalMidnight() const { |
(...skipping 16 matching lines...) Expand all Loading... |
93 PRStatus result = PR_ParseTimeString(ascii_time_string.c_str(), PR_FALSE, | 94 PRStatus result = PR_ParseTimeString(ascii_time_string.c_str(), PR_FALSE, |
94 &result_time); | 95 &result_time); |
95 if (PR_SUCCESS != result) | 96 if (PR_SUCCESS != result) |
96 return false; | 97 return false; |
97 result_time += kTimeTToMicrosecondsOffset; | 98 result_time += kTimeTToMicrosecondsOffset; |
98 *parsed_time = Time(result_time); | 99 *parsed_time = Time(result_time); |
99 return true; | 100 return true; |
100 } | 101 } |
101 | 102 |
102 } // namespace base | 103 } // namespace base |
OLD | NEW |