下面列出了java.text.DateFormatSymbols#getEras ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private String[] getFieldStrings(int field, int style, DateFormatSymbols symbols) {
String[] strings = null;
switch (field) {
case ERA:
strings = symbols.getEras();
break;
case MONTH:
strings = (style == LONG) ? symbols.getMonths() : symbols.getShortMonths();
break;
case DAY_OF_WEEK:
strings = (style == LONG) ? symbols.getWeekdays() : symbols.getShortWeekdays();
break;
case AM_PM:
strings = symbols.getAmPmStrings();
break;
}
return strings;
}
private String[] getFieldStrings(int field, int style, DateFormatSymbols symbols) {
int baseStyle = getBaseStyle(style); // ignore the standalone mask
// DateFormatSymbols doesn't support any narrow names.
if (baseStyle == NARROW_FORMAT) {
return null;
}
String[] strings = null;
switch (field) {
case ERA:
strings = symbols.getEras();
break;
case MONTH:
strings = (baseStyle == LONG) ? symbols.getMonths() : symbols.getShortMonths();
break;
case DAY_OF_WEEK:
strings = (baseStyle == LONG) ? symbols.getWeekdays() : symbols.getShortWeekdays();
break;
case AM_PM:
strings = symbols.getAmPmStrings();
break;
}
return strings;
}
private String[] getFieldStrings(int field, int style, DateFormatSymbols symbols) {
int baseStyle = getBaseStyle(style); // ignore the standalone mask
// DateFormatSymbols doesn't support any narrow names.
if (baseStyle == NARROW_FORMAT) {
return null;
}
String[] strings = null;
switch (field) {
case ERA:
strings = symbols.getEras();
break;
case MONTH:
strings = (baseStyle == LONG) ? symbols.getMonths() : symbols.getShortMonths();
break;
case DAY_OF_WEEK:
strings = (baseStyle == LONG) ? symbols.getWeekdays() : symbols.getShortWeekdays();
break;
case AM_PM:
strings = symbols.getAmPmStrings();
break;
}
return strings;
}
private static String[] getDisplayNameArray(int field, boolean isLong, Locale locale) {
DateFormatSymbols dfs = new DateFormatSymbols(locale);
switch (field) {
case Calendar.AM_PM:
return dfs.getAmPmStrings();
case Calendar.DAY_OF_WEEK:
return isLong ? dfs.getWeekdays() : dfs.getShortWeekdays();
case Calendar.ERA:
return dfs.getEras();
case Calendar.MONTH:
return isLong ? dfs.getMonths() : dfs.getShortMonths();
}
return null;
}
private String[] getFieldStrings(int field, int style, DateFormatSymbols symbols) {
int baseStyle = getBaseStyle(style); // ignore the standalone mask
// DateFormatSymbols doesn't support any narrow names.
if (baseStyle == NARROW_FORMAT) {
return null;
}
String[] strings = null;
switch (field) {
case ERA:
strings = symbols.getEras();
break;
case MONTH:
strings = (baseStyle == LONG) ? symbols.getMonths() : symbols.getShortMonths();
break;
case DAY_OF_WEEK:
strings = (baseStyle == LONG) ? symbols.getWeekdays() : symbols.getShortWeekdays();
break;
case AM_PM:
strings = symbols.getAmPmStrings();
break;
}
return strings;
}
private String[] getFieldStrings(int field, int style, DateFormatSymbols symbols) {
int baseStyle = getBaseStyle(style); // ignore the standalone mask
// DateFormatSymbols doesn't support any narrow names.
if (baseStyle == NARROW_FORMAT) {
return null;
}
String[] strings = null;
switch (field) {
case ERA:
strings = symbols.getEras();
break;
case MONTH:
strings = (baseStyle == LONG) ? symbols.getMonths() : symbols.getShortMonths();
break;
case DAY_OF_WEEK:
strings = (baseStyle == LONG) ? symbols.getWeekdays() : symbols.getShortWeekdays();
break;
case AM_PM:
strings = symbols.getAmPmStrings();
break;
}
return strings;
}
private String[] getFieldStrings(int field, int style, DateFormatSymbols symbols) {
int baseStyle = getBaseStyle(style); // ignore the standalone mask
// DateFormatSymbols doesn't support any narrow names.
if (baseStyle == NARROW_FORMAT) {
return null;
}
String[] strings = null;
switch (field) {
case ERA:
strings = symbols.getEras();
break;
case MONTH:
strings = (baseStyle == LONG) ? symbols.getMonths() : symbols.getShortMonths();
break;
case DAY_OF_WEEK:
strings = (baseStyle == LONG) ? symbols.getWeekdays() : symbols.getShortWeekdays();
break;
case AM_PM:
strings = symbols.getAmPmStrings();
break;
}
return strings;
}
private static String[] getDisplayNameArray(int field, boolean isLong, Locale locale) {
DateFormatSymbols dfs = new DateFormatSymbols(locale);
switch (field) {
case Calendar.AM_PM:
return dfs.getAmPmStrings();
case Calendar.DAY_OF_WEEK:
return isLong ? dfs.getWeekdays() : dfs.getShortWeekdays();
case Calendar.ERA:
return dfs.getEras();
case Calendar.MONTH:
return isLong ? dfs.getMonths() : dfs.getShortMonths();
}
return null;
}
private String[] getFieldStrings(int field, int style, DateFormatSymbols symbols) {
int baseStyle = getBaseStyle(style); // ignore the standalone mask
// DateFormatSymbols doesn't support any narrow names.
if (baseStyle == NARROW_FORMAT) {
return null;
}
String[] strings = null;
switch (field) {
case ERA:
strings = symbols.getEras();
break;
case MONTH:
strings = (baseStyle == LONG) ? symbols.getMonths() : symbols.getShortMonths();
break;
case DAY_OF_WEEK:
strings = (baseStyle == LONG) ? symbols.getWeekdays() : symbols.getShortWeekdays();
break;
case AM_PM:
strings = symbols.getAmPmStrings();
break;
}
return strings;
}
private String[] getFieldStrings(int field, int style, DateFormatSymbols symbols) {
int baseStyle = getBaseStyle(style); // ignore the standalone mask
// DateFormatSymbols doesn't support any narrow names.
if (baseStyle == NARROW_FORMAT) {
return null;
}
String[] strings = null;
switch (field) {
case ERA:
strings = symbols.getEras();
break;
case MONTH:
strings = (baseStyle == LONG) ? symbols.getMonths() : symbols.getShortMonths();
break;
case DAY_OF_WEEK:
strings = (baseStyle == LONG) ? symbols.getWeekdays() : symbols.getShortWeekdays();
break;
case AM_PM:
strings = symbols.getAmPmStrings();
break;
}
return strings;
}
private String[] getFieldStrings(int field, int style, DateFormatSymbols symbols) {
int baseStyle = getBaseStyle(style); // ignore the standalone mask
// DateFormatSymbols doesn't support any narrow names.
if (baseStyle == NARROW_FORMAT) {
return null;
}
String[] strings = null;
switch (field) {
case ERA:
strings = symbols.getEras();
break;
case MONTH:
strings = (baseStyle == LONG) ? symbols.getMonths() : symbols.getShortMonths();
break;
case DAY_OF_WEEK:
strings = (baseStyle == LONG) ? symbols.getWeekdays() : symbols.getShortWeekdays();
break;
case AM_PM:
strings = symbols.getAmPmStrings();
break;
}
return strings;
}
private String[] getFieldStrings(int field, int style, DateFormatSymbols symbols) {
int baseStyle = getBaseStyle(style); // ignore the standalone mask
// DateFormatSymbols doesn't support any narrow names.
if (baseStyle == NARROW_FORMAT) {
return null;
}
String[] strings = null;
switch (field) {
case ERA:
strings = symbols.getEras();
break;
case MONTH:
strings = (baseStyle == LONG) ? symbols.getMonths() : symbols.getShortMonths();
break;
case DAY_OF_WEEK:
strings = (baseStyle == LONG) ? symbols.getWeekdays() : symbols.getShortWeekdays();
break;
case AM_PM:
strings = symbols.getAmPmStrings();
break;
}
return strings;
}
public LocaledDateFormat(Locale locale) {
DateFormatSymbols dateFormatSymbols = new DateFormatSymbols(locale);
months = dateFormatSymbols.getMonths();
shortMonths = dateFormatSymbols.getShortMonths();
weekdays = dateFormatSymbols.getWeekdays();
shortWeekdays = dateFormatSymbols.getShortWeekdays();
eras = dateFormatSymbols.getEras();
ampms = dateFormatSymbols.getAmPmStrings();
}
private String[] getFieldStrings(int field, int style, DateFormatSymbols symbols) {
int baseStyle = getBaseStyle(style); // ignore the standalone mask
// DateFormatSymbols doesn't support any narrow names.
if (baseStyle == NARROW_FORMAT) {
return null;
}
String[] strings = null;
switch (field) {
case ERA:
strings = symbols.getEras();
break;
case MONTH:
strings = (baseStyle == LONG) ? symbols.getMonths() : symbols.getShortMonths();
break;
case DAY_OF_WEEK:
strings = (baseStyle == LONG) ? symbols.getWeekdays() : symbols.getShortWeekdays();
break;
case AM_PM:
strings = symbols.getAmPmStrings();
break;
}
return strings;
}
private String[] getFieldStrings(int field, int style, DateFormatSymbols symbols) {
int baseStyle = getBaseStyle(style); // ignore the standalone mask
// DateFormatSymbols doesn't support any narrow names.
if (baseStyle == NARROW_FORMAT) {
return null;
}
String[] strings = null;
switch (field) {
case ERA:
strings = symbols.getEras();
break;
case MONTH:
strings = (baseStyle == LONG) ? symbols.getMonths() : symbols.getShortMonths();
break;
case DAY_OF_WEEK:
strings = (baseStyle == LONG) ? symbols.getWeekdays() : symbols.getShortWeekdays();
break;
case AM_PM:
strings = symbols.getAmPmStrings();
break;
}
return strings;
}
public static void main(String[] args) throws Exception
{
DateFormatSymbols symbols = new DateFormatSymbols(Locale.JAPAN);
String[] eras = symbols.getEras();
System.out.println("BC = " + eras[0]);
if (!eras[0].equals(bc)) {
System.out.println("*** Should have been " + bc);
throw new Exception("Error in BC");
}
System.out.println("AD = " + eras[1]);
if (!eras[1].equals(ad)) {
System.out.println("*** Should have been " + ad);
throw new Exception("Error in AD");
}
String[][] zones = symbols.getZoneStrings();
for (int i = 0; i < zones.length; i++) {
if (!"Asia/Tokyo".equals(zones[i][0])) {
continue;
}
System.out.println("Long zone name = " + zones[i][1]);
if (!zones[i][1].equals(jstLong)) {
System.out.println("*** Should have been " + jstLong);
throw new Exception("Error in long TZ name");
}
System.out.println("Short zone name = " + zones[i][2]);
if (!zones[i][2].equals(jstShort)) {
System.out.println("*** Should have been " + jstShort);
throw new Exception("Error in short TZ name");
}
System.out.println("Long zone name = " + zones[i][3]);
if (!zones[i][3].equals(jdtLong)) {
System.out.println("*** Should have been " + jdtLong);
throw new Exception("Error in long TZ name");
}
System.out.println("SHORT zone name = " + zones[i][4]);
if (!zones[i][4].equals(jdtShort)) {
System.out.println("*** Should have been " + jdtShort);
throw new Exception("Error in short TZ name");
}
}
}
public static void main(String[] args) throws Exception
{
DateFormatSymbols symbols = new DateFormatSymbols(Locale.JAPAN);
String[] eras = symbols.getEras();
System.out.println("BC = " + eras[0]);
if (!eras[0].equals(bc)) {
System.out.println("*** Should have been " + bc);
throw new Exception("Error in BC");
}
System.out.println("AD = " + eras[1]);
if (!eras[1].equals(ad)) {
System.out.println("*** Should have been " + ad);
throw new Exception("Error in AD");
}
String[][] zones = symbols.getZoneStrings();
for (int i = 0; i < zones.length; i++) {
if (!"Asia/Tokyo".equals(zones[i][0])) {
continue;
}
System.out.println("Long zone name = " + zones[i][1]);
if (!zones[i][1].equals(jstLong)) {
System.out.println("*** Should have been " + jstLong);
throw new Exception("Error in long TZ name");
}
System.out.println("Short zone name = " + zones[i][2]);
if (!zones[i][2].equals(jstShort)) {
System.out.println("*** Should have been " + jstShort);
throw new Exception("Error in short TZ name");
}
System.out.println("Long zone name = " + zones[i][3]);
if (!zones[i][3].equals(jdtLong)) {
System.out.println("*** Should have been " + jdtLong);
throw new Exception("Error in long TZ name");
}
System.out.println("SHORT zone name = " + zones[i][4]);
if (!zones[i][4].equals(jdtShort)) {
System.out.println("*** Should have been " + jdtShort);
throw new Exception("Error in short TZ name");
}
}
}
public static void main(String[] args) throws Exception
{
DateFormatSymbols symbols = new DateFormatSymbols(Locale.JAPAN);
String[] eras = symbols.getEras();
System.out.println("BC = " + eras[0]);
if (!eras[0].equals(bc)) {
System.out.println("*** Should have been " + bc);
throw new Exception("Error in BC");
}
System.out.println("AD = " + eras[1]);
if (!eras[1].equals(ad)) {
System.out.println("*** Should have been " + ad);
throw new Exception("Error in AD");
}
String[][] zones = symbols.getZoneStrings();
for (int i = 0; i < zones.length; i++) {
if (!"Asia/Tokyo".equals(zones[i][0])) {
continue;
}
System.out.println("Long zone name = " + zones[i][1]);
if (!zones[i][1].equals(jstLong)) {
System.out.println("*** Should have been " + jstLong);
throw new Exception("Error in long TZ name");
}
System.out.println("Short zone name = " + zones[i][2]);
if (!zones[i][2].equals(jstShort)) {
System.out.println("*** Should have been " + jstShort);
throw new Exception("Error in short TZ name");
}
System.out.println("Long zone name = " + zones[i][3]);
if (!zones[i][3].equals(jdtLong)) {
System.out.println("*** Should have been " + jdtLong);
throw new Exception("Error in long TZ name");
}
System.out.println("SHORT zone name = " + zones[i][4]);
if (!zones[i][4].equals(jdtShort)) {
System.out.println("*** Should have been " + jdtShort);
throw new Exception("Error in short TZ name");
}
}
}
public static void main(String[] args) throws Exception
{
DateFormatSymbols symbols = new DateFormatSymbols(Locale.JAPAN);
String[] eras = symbols.getEras();
System.out.println("BC = " + eras[0]);
if (!eras[0].equals(bc)) {
System.out.println("*** Should have been " + bc);
throw new Exception("Error in BC");
}
System.out.println("AD = " + eras[1]);
if (!eras[1].equals(ad)) {
System.out.println("*** Should have been " + ad);
throw new Exception("Error in AD");
}
String[][] zones = symbols.getZoneStrings();
for (int i = 0; i < zones.length; i++) {
if (!"Asia/Tokyo".equals(zones[i][0])) {
continue;
}
System.out.println("Long zone name = " + zones[i][1]);
if (!zones[i][1].equals(jstLong)) {
System.out.println("*** Should have been " + jstLong);
throw new Exception("Error in long TZ name");
}
System.out.println("Short zone name = " + zones[i][2]);
if (!zones[i][2].equals(jstShort)) {
System.out.println("*** Should have been " + jstShort);
throw new Exception("Error in short TZ name");
}
System.out.println("Long zone name = " + zones[i][3]);
if (!zones[i][3].equals(jdtLong)) {
System.out.println("*** Should have been " + jdtLong);
throw new Exception("Error in long TZ name");
}
System.out.println("SHORT zone name = " + zones[i][4]);
if (!zones[i][4].equals(jdtShort)) {
System.out.println("*** Should have been " + jdtShort);
throw new Exception("Error in short TZ name");
}
}
}
/**
* @param locale must not be null
*/
private GJLocaleSymbols(Locale locale) {
iLocale = new WeakReference<Locale>(locale);
DateFormatSymbols dfs = DateTimeUtils.getDateFormatSymbols(locale);
iEras = dfs.getEras();
iDaysOfWeek = realignDaysOfWeek(dfs.getWeekdays());
iShortDaysOfWeek = realignDaysOfWeek(dfs.getShortWeekdays());
iMonths = realignMonths(dfs.getMonths());
iShortMonths = realignMonths(dfs.getShortMonths());
iHalfday = dfs.getAmPmStrings();
Integer[] integers = new Integer[13];
for (int i=0; i<13; i++) {
integers[i] = Integer.valueOf(i);
}
iParseEras = new TreeMap<String, Integer>(String.CASE_INSENSITIVE_ORDER);
addSymbols(iParseEras, iEras, integers);
if ("en".equals(locale.getLanguage())) {
// Include support for parsing "BCE" and "CE" if the language is
// English. At some point Joda-Time will need an independent set of
// localized symbols and not depend on java.text.DateFormatSymbols.
iParseEras.put("BCE", integers[0]);
iParseEras.put("CE", integers[1]);
}
iParseDaysOfWeek = new TreeMap<String, Integer>(String.CASE_INSENSITIVE_ORDER);
addSymbols(iParseDaysOfWeek, iDaysOfWeek, integers);
addSymbols(iParseDaysOfWeek, iShortDaysOfWeek, integers);
addNumerals(iParseDaysOfWeek, 1, 7, integers);
iParseMonths = new TreeMap<String, Integer>(String.CASE_INSENSITIVE_ORDER);
addSymbols(iParseMonths, iMonths, integers);
addSymbols(iParseMonths, iShortMonths, integers);
addNumerals(iParseMonths, 1, 12, integers);
iMaxEraLength = maxLength(iEras);
iMaxDayOfWeekLength = maxLength(iDaysOfWeek);
iMaxShortDayOfWeekLength = maxLength(iShortDaysOfWeek);
iMaxMonthLength = maxLength(iMonths);
iMaxShortMonthLength = maxLength(iShortMonths);
iMaxHalfdayLength = maxLength(iHalfday);
}