Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(673)

Side by Side Diff: base/time.cc

Issue 6903022: Removed wchar_t from Time::FromString (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Removed unnecessary blankline. Created 9 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « base/time.h ('k') | base/time_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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;
114 } 116 }
115 117
116 // Time::Exploded ------------------------------------------------------------- 118 // Time::Exploded -------------------------------------------------------------
117 119
118 inline bool is_in_range(int value, int lo, int hi) { 120 inline bool is_in_range(int value, int lo, int hi) {
119 return lo <= value && value <= hi; 121 return lo <= value && value <= hi;
120 } 122 }
121 123
122 bool Time::Exploded::HasValidValues() const { 124 bool Time::Exploded::HasValidValues() const {
123 return is_in_range(month, 1, 12) && 125 return is_in_range(month, 1, 12) &&
124 is_in_range(day_of_week, 0, 6) && 126 is_in_range(day_of_week, 0, 6) &&
125 is_in_range(day_of_month, 1, 31) && 127 is_in_range(day_of_month, 1, 31) &&
126 is_in_range(hour, 0, 23) && 128 is_in_range(hour, 0, 23) &&
127 is_in_range(minute, 0, 59) && 129 is_in_range(minute, 0, 59) &&
128 is_in_range(second, 0, 60) && 130 is_in_range(second, 0, 60) &&
129 is_in_range(millisecond, 0, 999); 131 is_in_range(millisecond, 0, 999);
130 } 132 }
131 133
132 } // namespace base 134 } // namespace base
OLDNEW
« no previous file with comments | « base/time.h ('k') | base/time_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698