OLD | NEW |
---|---|
1 // Copyright (c) 2009 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 |
11 namespace base { | 11 namespace base { |
(...skipping 79 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') |
105 return false; | 105 return false; |
106 | |
106 PRTime result_time = 0; | 107 PRTime result_time = 0; |
107 PRStatus result = PR_ParseTimeString(ascii_time_string.c_str(), PR_FALSE, | 108 PRStatus result = PR_ParseTimeString(time_string, PR_FALSE, |
108 &result_time); | 109 &result_time); |
109 if (PR_SUCCESS != result) | 110 if (PR_SUCCESS != result) |
110 return false; | 111 return false; |
112 | |
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 | |
wtc
2011/07/08 22:49:15
Remove this blank line.
shinyak (Google)
2011/07/13 14:34:46
Done.
| |
114 } | 117 } |
115 | 118 |
116 // Time::Exploded ------------------------------------------------------------- | 119 // Time::Exploded ------------------------------------------------------------- |
117 | 120 |
118 inline bool is_in_range(int value, int lo, int hi) { | 121 inline bool is_in_range(int value, int lo, int hi) { |
119 return lo <= value && value <= hi; | 122 return lo <= value && value <= hi; |
120 } | 123 } |
121 | 124 |
122 bool Time::Exploded::HasValidValues() const { | 125 bool Time::Exploded::HasValidValues() const { |
123 return is_in_range(month, 1, 12) && | 126 return is_in_range(month, 1, 12) && |
124 is_in_range(day_of_week, 0, 6) && | 127 is_in_range(day_of_week, 0, 6) && |
125 is_in_range(day_of_month, 1, 31) && | 128 is_in_range(day_of_month, 1, 31) && |
126 is_in_range(hour, 0, 23) && | 129 is_in_range(hour, 0, 23) && |
127 is_in_range(minute, 0, 59) && | 130 is_in_range(minute, 0, 59) && |
128 is_in_range(second, 0, 60) && | 131 is_in_range(second, 0, 60) && |
129 is_in_range(millisecond, 0, 999); | 132 is_in_range(millisecond, 0, 999); |
130 } | 133 } |
131 | 134 |
132 } // namespace base | 135 } // namespace base |
OLD | NEW |