ICU-11510 J: Support narrow AM/PM "aaaaa" for date format and parse
X-SVN-Rev: 37125
This commit is contained in:
parent
3076cb2149
commit
3765b3d130
@ -486,6 +486,14 @@ public class DateFormatSymbols implements Serializable, Cloneable {
|
||||
*/
|
||||
String ampms[] = null;
|
||||
|
||||
/**
|
||||
* narrow AM and PM strings. For example: "a" and "p". An array of
|
||||
* 2 strings, indexed by <code>Calendar.AM</code> and
|
||||
* <code>Calendar.PM</code>.
|
||||
* @serial
|
||||
*/
|
||||
String ampmsNarrow[] = null;
|
||||
|
||||
/**
|
||||
* Time separator string. For example: ":".
|
||||
* @serial
|
||||
@ -1415,6 +1423,7 @@ public class DateFormatSymbols implements Serializable, Cloneable {
|
||||
&& Utility.arrayEquals(standaloneShorterWeekdays, that.standaloneShorterWeekdays)
|
||||
&& Utility.arrayEquals(standaloneNarrowWeekdays, that.standaloneNarrowWeekdays)
|
||||
&& Utility.arrayEquals(ampms, that.ampms)
|
||||
&& Utility.arrayEquals(ampmsNarrow, that.ampmsNarrow)
|
||||
&& Utility.arrayEquals(timeSeparator, that.timeSeparator)
|
||||
&& arrayOfArrayEquals(zoneStrings, that.zoneStrings)
|
||||
// getDiplayName maps deprecated country and language codes to the current ones
|
||||
@ -1490,6 +1499,7 @@ public class DateFormatSymbols implements Serializable, Cloneable {
|
||||
this.standaloneShorterWeekdays = dfs.standaloneShorterWeekdays;
|
||||
this.standaloneNarrowWeekdays = dfs.standaloneNarrowWeekdays;
|
||||
this.ampms = dfs.ampms;
|
||||
this.ampmsNarrow = dfs.ampmsNarrow;
|
||||
this.timeSeparator = dfs.timeSeparator;
|
||||
this.shortQuarters = dfs.shortQuarters;
|
||||
this.quarters = dfs.quarters;
|
||||
@ -1593,6 +1603,7 @@ public class DateFormatSymbols implements Serializable, Cloneable {
|
||||
System.arraycopy(snWeekdays, 0, standaloneNarrowWeekdays, 1, snWeekdays.length);
|
||||
|
||||
ampms = calData.getStringArray("AmPmMarkers");
|
||||
ampmsNarrow = calData.getStringArray("AmPmMarkersNarrow");
|
||||
|
||||
quarters = calData.getStringArray("quarters", "wide");
|
||||
shortQuarters = calData.getStringArray("quarters", "abbreviated");
|
||||
|
@ -1686,7 +1686,12 @@ public class SimpleDateFormat extends DateFormat {
|
||||
}
|
||||
break;
|
||||
case 14: // 'a' - AM_PM
|
||||
safeAppend(formatData.ampms, value, buf);
|
||||
// formatData.ampmsNarrow may be null when deserializing DateFormatSymbolsfrom old version
|
||||
if (count < 5 || formatData.ampmsNarrow == null) {
|
||||
safeAppend(formatData.ampms, value, buf);
|
||||
} else {
|
||||
safeAppend(formatData.ampmsNarrow, value, buf);
|
||||
}
|
||||
break;
|
||||
case 15: // 'h' - HOUR (1..12)
|
||||
if (value == 0) {
|
||||
@ -3120,8 +3125,26 @@ public class SimpleDateFormat extends DateFormat {
|
||||
}
|
||||
return newStart;
|
||||
}
|
||||
case 14: // 'a' - AM_PM
|
||||
return matchString(text, start, Calendar.AM_PM, formatData.ampms, null, cal);
|
||||
case 14: { // 'a' - AM_PM
|
||||
// Optionally try both wide/abbrev and narrow forms.
|
||||
// formatData.ampmsNarrow may be null when deserializing DateFormatSymbolsfrom old version,
|
||||
// in which case our only option is wide form
|
||||
int newStart = 0;
|
||||
// try wide/abbrev a-aaaa
|
||||
if(formatData.ampmsNarrow == null || count < 5 || getBooleanAttribute(DateFormat.BooleanAttribute.PARSE_MULTIPLE_PATTERNS_FOR_MATCH)) {
|
||||
if ((newStart = matchString(text, start, Calendar.AM_PM, formatData.ampms, null, cal)) > 0) {
|
||||
return newStart;
|
||||
}
|
||||
}
|
||||
// try narrow aaaaa
|
||||
if(formatData.ampmsNarrow != null && (count >= 5 || getBooleanAttribute(DateFormat.BooleanAttribute.PARSE_MULTIPLE_PATTERNS_FOR_MATCH))) {
|
||||
if ((newStart = matchString(text, start, Calendar.AM_PM, formatData.ampmsNarrow, null, cal)) > 0) {
|
||||
return newStart;
|
||||
}
|
||||
}
|
||||
// no matches for given options
|
||||
return ~start;
|
||||
}
|
||||
case 15: // 'h' - HOUR (1..12)
|
||||
// [We computed 'value' above.]
|
||||
if (value == cal.getLeastMaximum(Calendar.HOUR)+1) {
|
||||
|
@ -2892,6 +2892,11 @@ public class DateFormatTest extends com.ibm.icu.dev.test.TestFmwk {
|
||||
"ccccc", "1970 01 01 0:00:00", "T",
|
||||
"ccccc", "1970 01 02 0:00:00", "F",
|
||||
"ccccc", "1970 01 03 0:00:00", "S",
|
||||
|
||||
"h:mm a", "2015 01 01 10:00:00", "10:00 AM",
|
||||
"h:mm a", "2015 01 01 22:00:00", "10:00 PM",
|
||||
"h:mm aaaaa", "2015 01 01 10:00:00", "10:00 a",
|
||||
"h:mm aaaaa", "2015 01 01 22:00:00", "10:00 p",
|
||||
};
|
||||
|
||||
String CS_DATA[] = {
|
||||
@ -2941,10 +2946,25 @@ public class DateFormatTest extends com.ibm.icu.dev.test.TestFmwk {
|
||||
"ccccc", "1970 01 01 0:00:00", "\u010C",
|
||||
"ccccc", "1970 01 02 0:00:00", "P",
|
||||
"ccccc", "1970 01 03 0:00:00", "S",
|
||||
|
||||
"h:mm a", "2015 01 01 10:00:00", "10:00 AM",
|
||||
"h:mm a", "2015 01 01 22:00:00", "10:00 PM",
|
||||
"h:mm aaaaa", "2015 01 01 10:00:00", "10:00 AM",
|
||||
"h:mm aaaaa", "2015 01 01 22:00:00", "10:00 PM",
|
||||
};
|
||||
|
||||
String CA_DATA[] = {
|
||||
"yyyy MM dd HH:mm:ss",
|
||||
|
||||
"h:mm a", "2015 01 01 10:00:00", "10:00 a. m.",
|
||||
"h:mm a", "2015 01 01 22:00:00", "10:00 p. m.",
|
||||
"h:mm aaaaa", "2015 01 01 10:00:00", "10:00 a.m.",
|
||||
"h:mm aaaaa", "2015 01 01 22:00:00", "10:00 p.m.",
|
||||
};
|
||||
|
||||
expectFormat(EN_DATA, new Locale("en", "", ""));
|
||||
expectFormat(CS_DATA, new Locale("cs", "", ""));
|
||||
expectFormat(CA_DATA, new Locale("ca", "", ""));
|
||||
}
|
||||
|
||||
public void TestEras()
|
||||
|
Loading…
Reference in New Issue
Block a user