OLD | NEW |
---|---|
1 // Copyright (c) 2009 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/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 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
91 Exploded exploded; | 91 Exploded exploded; |
92 LocalExplode(&exploded); | 92 LocalExplode(&exploded); |
93 exploded.hour = 0; | 93 exploded.hour = 0; |
94 exploded.minute = 0; | 94 exploded.minute = 0; |
95 exploded.second = 0; | 95 exploded.second = 0; |
96 exploded.millisecond = 0; | 96 exploded.millisecond = 0; |
97 return FromLocalExploded(exploded); | 97 return FromLocalExploded(exploded); |
98 } | 98 } |
99 | 99 |
100 // static | 100 // static |
101 bool Time::FromString(const wchar_t* time_string, Time* parsed_time) { | 101 bool Time::FromString(const char* time_string, Time* parsed_time) { |
102 DCHECK((time_string != NULL) && (parsed_time != NULL)); | 102 DCHECK((time_string != NULL) && (parsed_time != NULL)); |
103 std::string ascii_time_string = SysWideToUTF8(time_string); | 103 |
104 if (ascii_time_string.length() == 0) | 104 if (time_string[0] == '\0') { |
brettw
2011/04/26 15:33:03
Be consistent about {} usage for single-line condi
| |
105 return false; | 105 return false; |
106 } | |
107 | |
106 PRTime result_time = 0; | 108 PRTime result_time = 0; |
107 PRStatus result = PR_ParseTimeString(ascii_time_string.c_str(), PR_FALSE, | 109 PRStatus result = PR_ParseTimeString(time_string, PR_FALSE, |
108 &result_time); | 110 &result_time); |
109 if (PR_SUCCESS != result) | 111 if (PR_SUCCESS != result) |
110 return false; | 112 return false; |
111 result_time += kTimeTToMicrosecondsOffset; | 113 result_time += kTimeTToMicrosecondsOffset; |
112 *parsed_time = Time(result_time); | 114 *parsed_time = Time(result_time); |
113 return true; | 115 return true; |
116 | |
114 } | 117 } |
115 | 118 |
119 #if 0 | |
brettw
2011/04/26 15:33:03
Why is this here commented out?
| |
120 // static | |
121 bool Time::FromString(const wchar_t* time_string, Time* parsed_time) { | |
122 DCHECK((time_string != NULL) && (parsed_time != NULL)); | |
123 std::string ascii_time_string = SysWideToUTF8(time_string); | |
124 return FromString(ascii_time_string.c_str(), parsed_time); | |
125 } | |
126 #endif | |
127 | |
116 // Time::Exploded ------------------------------------------------------------- | 128 // Time::Exploded ------------------------------------------------------------- |
117 | 129 |
118 inline bool is_in_range(int value, int lo, int hi) { | 130 inline bool is_in_range(int value, int lo, int hi) { |
119 return lo <= value && value <= hi; | 131 return lo <= value && value <= hi; |
120 } | 132 } |
121 | 133 |
122 bool Time::Exploded::HasValidValues() const { | 134 bool Time::Exploded::HasValidValues() const { |
123 return is_in_range(month, 1, 12) && | 135 return is_in_range(month, 1, 12) && |
124 is_in_range(day_of_week, 0, 6) && | 136 is_in_range(day_of_week, 0, 6) && |
125 is_in_range(day_of_month, 1, 31) && | 137 is_in_range(day_of_month, 1, 31) && |
126 is_in_range(hour, 0, 23) && | 138 is_in_range(hour, 0, 23) && |
127 is_in_range(minute, 0, 59) && | 139 is_in_range(minute, 0, 59) && |
128 is_in_range(second, 0, 60) && | 140 is_in_range(second, 0, 60) && |
129 is_in_range(millisecond, 0, 999); | 141 is_in_range(millisecond, 0, 999); |
130 } | 142 } |
131 | 143 |
132 } // namespace base | 144 } // namespace base |
OLD | NEW |