MCPcopy Index your code
hub / github.com/apache/tomcat / convertDateFormat

Method convertDateFormat

java/org/apache/catalina/util/Strftime.java:160–207  ·  view source on GitHub ↗

Search the provided pattern and get the C standard Date/Time formatting rules and convert them to the Java equivalent. @param pattern The pattern to search @return The modified pattern

(String pattern)

Source from the content-addressed store, hash-verified

158 * @return The modified pattern
159 */
160 protected String convertDateFormat(String pattern) {
161 boolean inside = false;
162 boolean mark = false;
163 boolean modifiedCommand = false;
164
165 StringBuilder buf = new StringBuilder();
166
167 for (int i = 0; i < pattern.length(); i++) {
168 char c = pattern.charAt(i);
169
170 if (c == '%' && !mark) {
171 mark = true;
172 } else {
173 if (mark) {
174 if (modifiedCommand) {
175 // don't do anything--we just wanted to skip a char
176 modifiedCommand = false;
177 mark = false;
178 } else {
179 inside = translateCommand(buf, pattern, i, inside);
180 // It's a modifier code
181 if (c == 'O' || c == 'E') {
182 modifiedCommand = true;
183 } else {
184 mark = false;
185 }
186 }
187 } else {
188 if (!inside && c != ' ') {
189 // We start a literal, which we need to quote
190 buf.append('\'');
191 inside = true;
192 }
193
194 buf.append(c);
195 }
196 }
197 }
198
199 if (!buf.isEmpty()) {
200 char lastChar = buf.charAt(buf.length() - 1);
201
202 if (lastChar != '\'' && inside) {
203 buf.append('\'');
204 }
205 }
206 return buf.toString();
207 }
208
209 /**
210 * Quotes a string literal for use in a SimpleDateFormat pattern if it is

Callers 1

StrftimeMethod · 0.95

Calls 6

translateCommandMethod · 0.95
lengthMethod · 0.80
charAtMethod · 0.80
toStringMethod · 0.65
appendMethod · 0.45
isEmptyMethod · 0.45

Tested by

no test coverage detected