MCPcopy Create free account
hub / github.com/MenoData/Time4J / parse

Method parse

base/src/main/java/net/time4j/Meridiem.java:198–226  ·  view source on GitHub ↗
(
        CharSequence text,
        Locale locale,
        TextWidth width,
        OutputContext context
    )

Source from the content-addressed store, hash-verified

196 * @since 3.35/4.30
197 */
198 public static Meridiem parse(
199 CharSequence text,
200 Locale locale,
201 TextWidth width,
202 OutputContext context
203 ) throws ParseException {
204
205 if (text.length() == 2) {
206 char c2 = text.charAt(1);
207 if (c2 == 'M' || c2 == 'm') {
208 char c1 = text.charAt(0);
209 if (c1 == 'A' || c1 == 'a') {
210 return Meridiem.AM;
211 } else if (c1 == 'P' || c1 == 'p') {
212 return Meridiem.PM;
213 }
214 }
215 }
216
217 ParsePosition pp = new ParsePosition(0);
218 Meridiem m = CalendarText.getIsoInstance(locale).getMeridiems(width, context).parse(text, pp, Meridiem.class);
219
220 if (m == null) {
221 throw new ParseException("Cannot parse: " + text, pp.getErrorIndex());
222 } else {
223 return m;
224 }
225
226 }
227
228 @Override
229 public boolean test(WallTime context) {

Callers 1

parseMeridiemNameMethod · 0.95

Calls 5

getIsoInstanceMethod · 0.95
getMeridiemsMethod · 0.80
getErrorIndexMethod · 0.80
parseMethod · 0.65
lengthMethod · 0.45

Tested by 1

parseMeridiemNameMethod · 0.76