patternCharIndex == 15 /*'h' HOUR1_FIELD*/ ||
(patternCharIndex == 2 /*'M' MONTH_FIELD*/ && count <= 2) ||
(patternCharIndex == 26 /*'L' STAND_ALONE_MONTH*/ && count <= 2) ||
+ (patternCharIndex == 19 /*'e' DOW_LOCAL*/ && count <= 2) ||
patternCharIndex == 1 /*'y' YEAR */ || patternCharIndex == 18 /*'Y' YEAR_WOY */ ||
patternCharIndex == 30 /*'U' YEAR_NAME_FIELD, falls back to numeric */ ||
(patternCharIndex == 0 /*'G' ERA */ && isChineseCalendar) ||
}
cal.set(Calendar.MILLISECOND, value);
return pos.getIndex();
+ case 19: // 'e' - DOW_LOCAL
+ if(count <= 2) { // i.e. e/ee
+ cal.set(field, value);
+ return pos.getIndex();
+ }
+ // else for eee-eeeeee, fall through to EEE-EEEEEE handling
+ //$FALL-THROUGH$
case 9: { // 'E' - DAY_OF_WEEK
- // Want to be able to parse at least wide, abbrev, short forms.
- int newStart = matchString(text, start, Calendar.DAY_OF_WEEK, formatData.weekdays, null, cal); // try EEEE wide
- if (newStart > 0) {
+ // Want to be able to parse at least wide, abbrev, short, and narrow forms.
+ int newStart = 0;
+ if ((newStart = matchString(text, start, Calendar.DAY_OF_WEEK, formatData.weekdays, null, cal)) > 0) { // try EEEE wide
return newStart;
- } else if ((newStart = matchString(text, start, Calendar.DAY_OF_WEEK, formatData.shortWeekdays, null, cal)) > 0) { // try EEE abbrev
+ }
+ if ((newStart = matchString(text, start, Calendar.DAY_OF_WEEK, formatData.shortWeekdays, null, cal)) > 0) { // try EEE abbrev
return newStart;
- } else if (formatData.shorterWeekdays != null) {
- return matchString(text, start, Calendar.DAY_OF_WEEK, formatData.shorterWeekdays, null, cal); // try EEEEEE short
+ }
+ if (formatData.shorterWeekdays != null) {
+ if((newStart = matchString(text, start, Calendar.DAY_OF_WEEK, formatData.shorterWeekdays, null, cal)) > 0) { // try EEEEEE short
+ return newStart;
+ }
+ }
+ if (formatData.narrowWeekdays != null) {
+ if((newStart = matchString(text, start, Calendar.DAY_OF_WEEK, formatData.narrowWeekdays, null, cal)) > 0) { // try EEEEE narrow
+ return newStart;
+ }
}
return newStart;
}
// case 11: // 'F' - DAY_OF_WEEK_IN_MONTH
// case 12: // 'w' - WEEK_OF_YEAR
// case 13: // 'W' - WEEK_OF_MONTH
- // case 16: // 'K' - HOUR (0..11)
- // case 19: // 'e' - DOW_LOCAL
+ // case 16: // 'K' - HOUR (0..11)
// case 20: // 'u' - EXTENDED_YEAR
// case 21: // 'g' - JULIAN_DAY
// case 22: // 'A' - MILLISECONDS_IN_DAY
}
errln("No exception thrown at all for bad pattern!");
}
+
+ public void TestT10239() {
+
+ class TestDateFormatItem {
+ public String parseString;
+ public String pattern;
+ public String expectedResult; // null indicates expected error
+ // Simple constructor
+ public TestDateFormatItem(String parString, String patt, String expResult) {
+ pattern = patt;
+ parseString = parString;
+ expectedResult = expResult;
+ }
+ };
+
+ final TestDateFormatItem[] items = {
+ // parse String pattern expected result
+ new TestDateFormatItem("1 Oct 13 2013", "e MMM dd yyyy", "1 Oct 13 2013"),
+ new TestDateFormatItem("02 Oct 14 2013", "ee MMM dd yyyy", "02 Oct 14 2013"),
+ new TestDateFormatItem("Tue Oct 15 2013", "eee MMM dd yyyy", "Tue Oct 15 2013"),
+ new TestDateFormatItem("Wednesday Oct 16 2013", "eeee MMM dd yyyy", "Wednesday Oct 16 2013"),
+ new TestDateFormatItem("Th Oct 17 2013", "eeeeee MMM dd yyyy", "Th Oct 17 2013"),
+ new TestDateFormatItem("Fr Oct 18 2013", "EEEEEE MMM dd yyyy", "Fr Oct 18 2013"),
+ new TestDateFormatItem("S Oct 19 2013", "eeeee MMM dd yyyy", "S Oct 19 2013"),
+ new TestDateFormatItem("S Oct 20 2013", "EEEEE MMM dd yyyy", "S Oct 20 2013"),
+ };
+
+ StringBuffer result = new StringBuffer();
+ Date d = new Date();
+ Calendar cal = GregorianCalendar.getInstance(TimeZone.getTimeZone("GMT"), Locale.US);
+ SimpleDateFormat sdfmt = new SimpleDateFormat();
+ ParsePosition p = new ParsePosition(0);
+ for (TestDateFormatItem item: items) {
+ cal.clear();
+ sdfmt.setCalendar(cal);
+ sdfmt.applyPattern(item.pattern);
+ result.setLength(0);
+ p.setIndex(0);
+ p.setErrorIndex(-1);
+ d = sdfmt.parse(item.parseString, p);
+ if(item.expectedResult == null) {
+ if(p.getErrorIndex() != -1)
+ continue;
+ else
+ errln("error: unexpected parse success..."+item.parseString + " should have failed");
+ }
+ if(p.getErrorIndex() != -1) {
+ errln("error: parse error for string " +item.parseString + " against pattern " + item.pattern + " -- idx["+p.getIndex()+"] errIdx["+p.getErrorIndex()+"]");
+ continue;
+ }
+ cal.setTime(d);
+ result = sdfmt.format(cal, result, new FieldPosition(0));
+ if(!result.toString().equalsIgnoreCase(item.expectedResult)) {
+ errln("error: unexpected format result. expected - " + item.expectedResult + " but result was - " + result);
+ } else {
+ logln("formatted results match! - " + result.toString());
+ }
+ }
+ }
}