ICU-4327 Add long eras, narrow/standalone dates
X-SVN-Rev: 18137
This commit is contained in:
parent
13840ac3e5
commit
3828cdd422
@ -79,6 +79,28 @@ public class CalendarData {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Load data for calendar. Note, this object owns the resources, do NOT call ures_close()!
|
||||
* data is located in: "calendar/key/contextKey/subKey"
|
||||
* for example, calendar/dayNames/stand-alone/narrow
|
||||
*
|
||||
* @param key Resource key to data
|
||||
* @param contextKey Resource key to data
|
||||
* @param subKey Resource key to data
|
||||
* @internal
|
||||
*/
|
||||
public ICUResourceBundle get(String key, String contextKey, String subKey) {
|
||||
try {
|
||||
return fBundle.getWithFallback("calendar/" + fMainType + "/" + key + "/" + contextKey + "/" + subKey);
|
||||
} catch(MissingResourceException m) {
|
||||
if(fFallbackType != null) {
|
||||
return fBundle.getWithFallback("calendar/" + fFallbackType + "/" + key + "/" + contextKey + "/" + subKey);
|
||||
}
|
||||
throw m;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public String[] getStringArray(String key) {
|
||||
return get(key).getStringArray();
|
||||
@ -87,6 +109,10 @@ public class CalendarData {
|
||||
public String[] getStringArray(String key, String subKey) {
|
||||
return get(key, subKey).getStringArray();
|
||||
}
|
||||
|
||||
public String[] getStringArray(String key, String contextKey, String subKey) {
|
||||
return get(key, contextKey, subKey).getStringArray();
|
||||
}
|
||||
public String[] getEras(String subkey){
|
||||
ICUResourceBundle bundle = get("eras/"+subkey);
|
||||
return bundle.getStringArray();
|
||||
|
@ -354,8 +354,36 @@ public class DateFormatSymbols implements Serializable, Cloneable {
|
||||
* @draft ICU 3.4
|
||||
*/
|
||||
public String[] getMonths(int context, int width) {
|
||||
// TODO: Make this actually do something, just a placeholder right now.
|
||||
return duplicate(months);
|
||||
String [] returnValue = null;
|
||||
switch (context) {
|
||||
case FORMAT :
|
||||
switch(width) {
|
||||
case WIDE :
|
||||
returnValue = months;
|
||||
break;
|
||||
case ABBREVIATED :
|
||||
returnValue = shortMonths;
|
||||
break;
|
||||
case NARROW :
|
||||
returnValue = narrowMonths;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case STANDALONE :
|
||||
switch(width) {
|
||||
case WIDE :
|
||||
returnValue = standaloneMonths;
|
||||
break;
|
||||
case ABBREVIATED :
|
||||
returnValue = standaloneShortMonths;
|
||||
break;
|
||||
case NARROW :
|
||||
returnValue = standaloneNarrowMonths;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
return duplicate(returnValue);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -405,8 +433,36 @@ public class DateFormatSymbols implements Serializable, Cloneable {
|
||||
* @draft ICU 3.4
|
||||
*/
|
||||
public String[] getWeekdays(int context, int width) {
|
||||
// TODO: Make this actually do something, just a placeholder right now.
|
||||
return duplicate(weekdays);
|
||||
String [] returnValue = null;
|
||||
switch (context) {
|
||||
case FORMAT :
|
||||
switch(width) {
|
||||
case WIDE :
|
||||
returnValue = weekdays;
|
||||
break;
|
||||
case ABBREVIATED :
|
||||
returnValue = shortWeekdays;
|
||||
break;
|
||||
case NARROW :
|
||||
returnValue = narrowWeekdays;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case STANDALONE :
|
||||
switch(width) {
|
||||
case WIDE :
|
||||
returnValue = standaloneWeekdays;
|
||||
break;
|
||||
case ABBREVIATED :
|
||||
returnValue = standaloneShortWeekdays;
|
||||
break;
|
||||
case NARROW :
|
||||
returnValue = standaloneNarrowWeekdays;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
return duplicate(returnValue);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -535,10 +591,19 @@ public class DateFormatSymbols implements Serializable, Cloneable {
|
||||
if (obj == null || getClass() != obj.getClass()) return false;
|
||||
DateFormatSymbols that = (DateFormatSymbols) obj;
|
||||
return (Utility.arrayEquals(eras, that.eras)
|
||||
&& Utility.arrayEquals(eraNames, that.eraNames)
|
||||
&& Utility.arrayEquals(months, that.months)
|
||||
&& Utility.arrayEquals(shortMonths, that.shortMonths)
|
||||
&& Utility.arrayEquals(narrowMonths, that.narrowMonths)
|
||||
&& Utility.arrayEquals(standaloneMonths, that.standaloneMonths)
|
||||
&& Utility.arrayEquals(standaloneShortMonths, that.standaloneShortMonths)
|
||||
&& Utility.arrayEquals(standaloneNarrowMonths, that.standaloneNarrowMonths)
|
||||
&& Utility.arrayEquals(weekdays, that.weekdays)
|
||||
&& Utility.arrayEquals(shortWeekdays, that.shortWeekdays)
|
||||
&& Utility.arrayEquals(narrowWeekdays, that.narrowWeekdays)
|
||||
&& Utility.arrayEquals(standaloneWeekdays, that.standaloneWeekdays)
|
||||
&& Utility.arrayEquals(standaloneShortWeekdays, that.standaloneShortWeekdays)
|
||||
&& Utility.arrayEquals(standaloneNarrowWeekdays, that.standaloneNarrowWeekdays)
|
||||
&& Utility.arrayEquals(ampms, that.ampms)
|
||||
&& Utility.arrayEquals(zoneStrings, that.zoneStrings)
|
||||
&& Utility.arrayEquals(localPatternChars,
|
||||
@ -578,9 +643,50 @@ public class DateFormatSymbols implements Serializable, Cloneable {
|
||||
// getObject(). This won't be necessary if the Resource itself
|
||||
// is cached.
|
||||
eras = calData.getEras("abbreviated");
|
||||
|
||||
try {
|
||||
eraNames = calData.getEras("wide");
|
||||
}
|
||||
catch (MissingResourceException e) {
|
||||
eraNames = calData.getEras("abbreviated");
|
||||
}
|
||||
|
||||
months = calData.getStringArray("monthNames", "wide");
|
||||
shortMonths = calData.getStringArray("monthNames", "abbreviated");
|
||||
|
||||
try {
|
||||
narrowMonths = calData.getStringArray("monthNames", "narrow");
|
||||
}
|
||||
catch (MissingResourceException e) {
|
||||
narrowMonths = calData.getStringArray("monthNames", "abbreviated");
|
||||
}
|
||||
|
||||
try {
|
||||
standaloneMonths = calData.getStringArray("monthNames", "stand-alone", "wide");
|
||||
}
|
||||
catch (MissingResourceException e) {
|
||||
standaloneMonths = calData.getStringArray("monthNames", "format", "wide");
|
||||
}
|
||||
|
||||
try {
|
||||
standaloneShortMonths = calData.getStringArray("monthNames", "stand-alone", "abbreviated");
|
||||
}
|
||||
catch (MissingResourceException e) {
|
||||
standaloneShortMonths = calData.getStringArray("monthNames", "format", "abbreviated");
|
||||
}
|
||||
|
||||
try {
|
||||
standaloneNarrowMonths = calData.getStringArray("monthNames", "stand-alone", "narrow");
|
||||
}
|
||||
catch (MissingResourceException e) {
|
||||
try {
|
||||
standaloneNarrowMonths = calData.getStringArray("monthNames", "format", "narrow");
|
||||
}
|
||||
catch (MissingResourceException e1) {
|
||||
standaloneNarrowMonths = calData.getStringArray("monthNames", "format", "abbreviated");
|
||||
}
|
||||
}
|
||||
|
||||
String[] lWeekdays = calData.getStringArray("dayNames", "wide");
|
||||
weekdays = new String[8];
|
||||
weekdays[0] = ""; // 1-based
|
||||
@ -591,6 +697,55 @@ public class DateFormatSymbols implements Serializable, Cloneable {
|
||||
shortWeekdays[0] = ""; // 1-based
|
||||
System.arraycopy(sWeekdays, 0, shortWeekdays, 1, sWeekdays.length);
|
||||
|
||||
String [] nWeekdays = null;
|
||||
try {
|
||||
nWeekdays = calData.getStringArray("dayNames", "narrow");
|
||||
}
|
||||
catch (MissingResourceException e) {
|
||||
nWeekdays = calData.getStringArray("dayNames", "abbreviated");
|
||||
}
|
||||
narrowWeekdays = new String[8];
|
||||
narrowWeekdays[0] = ""; // 1-based
|
||||
System.arraycopy(nWeekdays, 0, narrowWeekdays, 1, nWeekdays.length);
|
||||
|
||||
String [] saWeekdays = null;
|
||||
try {
|
||||
saWeekdays = calData.getStringArray("dayNames", "stand-alone", "wide");
|
||||
}
|
||||
catch (MissingResourceException e) {
|
||||
saWeekdays = calData.getStringArray("dayNames", "format", "wide");
|
||||
}
|
||||
standaloneWeekdays = new String[8];
|
||||
standaloneWeekdays[0] = ""; // 1-based
|
||||
System.arraycopy(saWeekdays, 0, standaloneWeekdays, 1, saWeekdays.length);
|
||||
|
||||
String [] ssWeekdays = null;
|
||||
try {
|
||||
ssWeekdays = calData.getStringArray("dayNames", "stand-alone", "abbreviated");
|
||||
}
|
||||
catch (MissingResourceException e) {
|
||||
ssWeekdays = calData.getStringArray("dayNames", "format", "abbreviated");
|
||||
}
|
||||
standaloneShortWeekdays = new String[8];
|
||||
standaloneShortWeekdays[0] = ""; // 1-based
|
||||
System.arraycopy(ssWeekdays, 0, standaloneShortWeekdays, 1, ssWeekdays.length);
|
||||
|
||||
String [] snWeekdays = null;
|
||||
try {
|
||||
snWeekdays = calData.getStringArray("dayNames", "stand-alone", "narrow");
|
||||
}
|
||||
catch (MissingResourceException e) {
|
||||
try {
|
||||
snWeekdays = calData.getStringArray("dayNames", "format", "narrow");
|
||||
}
|
||||
catch (MissingResourceException e1) {
|
||||
snWeekdays = calData.getStringArray("dayNames", "format", "abbreviated");
|
||||
}
|
||||
}
|
||||
standaloneNarrowWeekdays = new String[8];
|
||||
standaloneNarrowWeekdays[0] = ""; // 1-based
|
||||
System.arraycopy(snWeekdays, 0, standaloneNarrowWeekdays, 1, snWeekdays.length);
|
||||
|
||||
ampms = calData.getStringArray("AmPmMarkers");
|
||||
|
||||
// These really do use rb and not calData
|
||||
@ -684,10 +839,19 @@ public class DateFormatSymbols implements Serializable, Cloneable {
|
||||
private final void copyMembers(DateFormatSymbols src, DateFormatSymbols dst)
|
||||
{
|
||||
dst.eras = duplicate(src.eras);
|
||||
dst.eraNames = duplicate(src.eraNames);
|
||||
dst.months = duplicate(src.months);
|
||||
dst.shortMonths = duplicate(src.shortMonths);
|
||||
dst.narrowMonths = duplicate(src.narrowMonths);
|
||||
dst.standaloneMonths = duplicate(src.standaloneMonths);
|
||||
dst.standaloneShortMonths = duplicate(src.standaloneShortMonths);
|
||||
dst.standaloneNarrowMonths = duplicate(src.standaloneNarrowMonths);
|
||||
dst.weekdays = duplicate(src.weekdays);
|
||||
dst.shortWeekdays = duplicate(src.shortWeekdays);
|
||||
dst.narrowWeekdays = duplicate(src.narrowWeekdays);
|
||||
dst.standaloneWeekdays = duplicate(src.standaloneWeekdays);
|
||||
dst.standaloneShortWeekdays = duplicate(src.standaloneShortWeekdays);
|
||||
dst.standaloneNarrowWeekdays = duplicate(src.standaloneNarrowWeekdays);
|
||||
dst.ampms = duplicate(src.ampms);
|
||||
dst.zoneStrings = duplicate(src.zoneStrings);
|
||||
dst.localPatternChars = new String (src.localPatternChars);
|
||||
|
@ -730,7 +730,10 @@ public class SimpleDateFormat extends DateFormat {
|
||||
|
||||
switch (patternCharIndex) {
|
||||
case 0: // 'G' - ERA
|
||||
buf.append(formatData.eras[value]);
|
||||
if (count >= 4)
|
||||
buf.append(formatData.eraNames[value]);
|
||||
else
|
||||
buf.append(formatData.eras[value]);
|
||||
break;
|
||||
case 1: // 'y' - YEAR
|
||||
/* According to the specification, if the number of pattern letters ('y') is 2,
|
||||
@ -745,7 +748,9 @@ public class SimpleDateFormat extends DateFormat {
|
||||
zeroPaddingNumber(buf, value, count, maxIntCount);
|
||||
break;
|
||||
case 2: // 'M' - MONTH
|
||||
if (count >= 4)
|
||||
if (count == 5)
|
||||
buf.append(formatData.narrowMonths[value]);
|
||||
else if (count == 4)
|
||||
buf.append(formatData.months[value]);
|
||||
else if (count == 3)
|
||||
buf.append(formatData.shortMonths[value]);
|
||||
@ -850,6 +855,26 @@ public class SimpleDateFormat extends DateFormat {
|
||||
zeroPaddingNumber(buf, value, 4, 4);
|
||||
}
|
||||
break;
|
||||
case 25: // 'c' - STANDALONE DAY
|
||||
if (count == 5)
|
||||
buf.append(formatData.standaloneNarrowWeekdays[value]);
|
||||
else if (count == 4)
|
||||
buf.append(formatData.standaloneWeekdays[value]);
|
||||
else if (count == 3)
|
||||
buf.append(formatData.standaloneShortWeekdays[value]);
|
||||
else
|
||||
zeroPaddingNumber(buf, value, 1, maxIntCount);
|
||||
break;
|
||||
case 26: // 'L' - STANDALONE MONTH
|
||||
if (count == 5)
|
||||
buf.append(formatData.standaloneNarrowMonths[value]);
|
||||
else if (count == 4)
|
||||
buf.append(formatData.standaloneMonths[value]);
|
||||
else if (count == 3)
|
||||
buf.append(formatData.standaloneShortMonths[value]);
|
||||
else
|
||||
zeroPaddingNumber(buf, value+1, count, maxIntCount);
|
||||
break;
|
||||
default:
|
||||
// case 3: // 'd' - DATE
|
||||
// case 5: // 'H' - HOUR_OF_DAY (0..23)
|
||||
|
Loading…
Reference in New Issue
Block a user