/** * Parses a timestamp string off the beginning of the string segment 'seg'. * Goes through each possible valid timestamp format until it finds a match. * The position where the parsing left off is stored in pp. * * @param seg The string segment being parsed. * @param pp Where parsing last left off. * @return An object representing a timestamp. */ CalendarP parseDate(String seg, ParsePosition pp) { CalendarP cal = null; for (int i = 0; i < validTimestampFormats.length && cal == null; i++) { pp.setIndex(0); SimpleDateFormat f = validTimestampFormats[i]; Date d = f.parse(seg, pp); int idx = pp.getIndex(); if (idx != 0) { // it only counts if the next character is '-', 'space', or end-of-string. char c = (seg.length() == idx ? 0 : seg.charAt(idx)); if (c == 0 || c == '-' || Character.isWhitespace(c)) cal = new CalendarP(d, getPrecisionField(f.toPattern())); } } if (cal == null) throw new FormattedRuntimeException("Invalid date encountered: ''{0}''", seg); return cal; }
/** * Parses a timestamp string off the beginning of the string segment 'seg'. * Goes through each possible valid timestamp format until it finds a match. * The position where the parsing left off is stored in pp. * * @param seg The string segment being parsed. * @param pp Where parsing last left off. * @return An object representing a timestamp. */ CalendarP parseDate(String seg, ParsePosition pp) { CalendarP cal = null; for (int i = 0; i < validTimestampFormats.length && cal == null; i++) { pp.setIndex(0); SimpleDateFormat f = validTimestampFormats[i]; Date d = f.parse(seg, pp); int idx = pp.getIndex(); if (idx != 0) { // it only counts if the next character is '-', 'space', or end-of-string. char c = (seg.length() == idx ? 0 : seg.charAt(idx)); if (c == 0 || c == '-' || Character.isWhitespace(c)) cal = new CalendarP(d, getPrecisionField(f.toPattern())); } } if (cal == null) throw new FormattedRuntimeException("Invalid date encountered: ''{0}''", seg); return cal; }
/** * Parses a timestamp string off the beginning of the string segment 'seg'. * Goes through each possible valid timestamp format until it finds a match. * The position where the parsing left off is stored in pp. * * @param seg The string segment being parsed. * @param pp Where parsing last left off. * @return An object representing a timestamp. */ CalendarP parseDate(String seg, ParsePosition pp) { CalendarP cal = null; for (int i = 0; i < validTimestampFormats.length && cal == null; i++) { pp.setIndex(0); SimpleDateFormat f = validTimestampFormats[i]; Date d = f.parse(seg, pp); int idx = pp.getIndex(); if (idx != 0) { // it only counts if the next character is '-', 'space', or end-of-string. char c = (seg.length() == idx ? 0 : seg.charAt(idx)); if (c == 0 || c == '-' || Character.isWhitespace(c)) cal = new CalendarP(d, getPrecisionField(f.toPattern())); } } if (cal == null) throw new FormattedRuntimeException("Invalid date encountered: ''{0}''", seg); return cal; }