/* ******************************************************************************* * Copyright (C) 1996-2010, International Business Machines Corporation and * * others. All Rights Reserved. * ******************************************************************************* */ package com.ibm.icu.text; import java.io.IOException; import java.io.ObjectInputStream; import java.io.Serializable; import java.util.Locale; import java.util.MissingResourceException; import java.util.ResourceBundle; import com.ibm.icu.impl.CalendarData; import com.ibm.icu.impl.CalendarUtil; import com.ibm.icu.impl.ICUCache; import com.ibm.icu.impl.ICUResourceBundle; import com.ibm.icu.impl.SimpleCache; import com.ibm.icu.impl.Utility; import com.ibm.icu.impl.ZoneMeta; import com.ibm.icu.impl.ZoneStringFormat; import com.ibm.icu.util.Calendar; import com.ibm.icu.util.ULocale; import com.ibm.icu.util.UResourceBundle; /** * {@icuenhanced java.text.DateFormatSymbols}.{@icu _usage_} * *

DateFormatSymbols is a public class for encapsulating * localizable date-time formatting data, such as the names of the * months, the names of the days of the week, and the time zone data. * DateFormat and SimpleDateFormat both use * DateFormatSymbols to encapsulate this information. * *

Typically you shouldn't use DateFormatSymbols directly. * Rather, you are encouraged to create a date-time formatter with the * DateFormat class's factory methods: getTimeInstance, * getDateInstance, or getDateTimeInstance. * These methods automatically create a DateFormatSymbols for * the formatter so that you don't have to. After the * formatter is created, you may modify its format pattern using the * setPattern method. For more information about * creating formatters using DateFormat's factory methods, * see {@link DateFormat}. * *

If you decide to create a date-time formatter with a specific * format pattern for a specific locale, you can do so with: *

*
 * new SimpleDateFormat(aPattern, new DateFormatSymbols(aLocale)).
 * 
*
* *

DateFormatSymbols objects are clonable. When you obtain * a DateFormatSymbols object, feel free to modify the * date-time formatting data. For instance, you can replace the localized * date-time format pattern characters with the ones that you feel easy * to remember. Or you can change the representative cities * to your favorite ones. * *

New DateFormatSymbols subclasses may be added to support * SimpleDateFormat for date-time formatting for additional locales. * * @see DateFormat * @see SimpleDateFormat * @see com.ibm.icu.util.SimpleTimeZone * @author Chen-Lieh Huang * @stable ICU 2.0 */ public class DateFormatSymbols implements Serializable, Cloneable { // TODO make sure local pattern char string is 18 characters long, // that is, that it encompasses the new 'u' char for // EXTENDED_YEAR. Two options: 1. Make sure resource data is // correct; 2. Make code add in 'u' at end if len == 17. // Constants for context /** * {@icu} Constant for context. * @stable ICU 3.6 */ public static final int FORMAT = 0; /** * {@icu} Constant for context. * @stable ICU 3.6 */ public static final int STANDALONE = 1; /** * {@icu} Constant for context. * @internal * @deprecated This API is ICU internal only. */ public static final int DT_CONTEXT_COUNT = 2; // Constants for width /** * {@icu} Constant for width. * @stable ICU 3.6 */ public static final int ABBREVIATED = 0; /** * {@icu} Constant for width. * @stable ICU 3.6 */ public static final int WIDE = 1; /** * {@icu} Constant for width. * @stable ICU 3.6 */ public static final int NARROW = 2; /** * {@icu} Constant for width. * @internal * @deprecated This API is ICU internal only. */ public static final int DT_WIDTH_COUNT = 3; /** * Constructs a DateFormatSymbols object by loading format data from * resources for the default locale. * * @throws java.util.MissingResourceException if the resources for the default locale * cannot be found or cannot be loaded. * @stable ICU 2.0 */ public DateFormatSymbols() { this(ULocale.getDefault()); } /** * Constructs a DateFormatSymbols object by loading format data from * resources for the given locale. * * @throws java.util.MissingResourceException if the resources for the specified * locale cannot be found or cannot be loaded. * @stable ICU 2.0 */ public DateFormatSymbols(Locale locale) { this(ULocale.forLocale(locale)); } /** * {@icu} Constructs a DateFormatSymbols object by loading format data from * resources for the given ulocale. * * @throws java.util.MissingResourceException if the resources for the specified * locale cannot be found or cannot be loaded. * @stable ICU 3.2 */ public DateFormatSymbols(ULocale locale) { initializeData(locale, CalendarUtil.getCalendarType(locale)); } /** * Returns a DateFormatSymbols instance for the default locale. * * {@icunote} Unlike java.text.DateFormatSymbols#getInstance, * this method simply returns new com.ibm.icu.text.DateFormatSymbols(). * ICU does not support DateFormatSymbolsProvider introduced in Java 6 * or its equivalent implementation for now. * * @return A DateFormatSymbols instance. * @stable ICU 3.8 */ public static DateFormatSymbols getInstance() { return new DateFormatSymbols(); } /** * Returns a DateFormatSymbols instance for the given locale. * * {@icunote} Unlike java.text.DateFormatSymbols#getInstance, * this method simply returns new com.ibm.icu.text.DateFormatSymbols(locale). * ICU does not support DateFormatSymbolsProvider introduced in Java 6 * or its equivalent implementation for now. * * @param locale the locale. * @return A DateFormatSymbols instance. * @stable ICU 3.8 */ public static DateFormatSymbols getInstance(Locale locale) { return new DateFormatSymbols(locale); } /** * {@icu} Returns a DateFormatSymbols instance for the given locale. * * {@icunote} Unlike java.text.DateFormatSymbols#getInstance, * this method simply returns new com.ibm.icu.text.DateFormatSymbols(locale). * ICU does not support DateFormatSymbolsProvider introduced in Java 6 * or its equivalent implementation for now. * * @param locale the locale. * @return A DateFormatSymbols instance. * @stable ICU 3.8 */ public static DateFormatSymbols getInstance(ULocale locale) { return new DateFormatSymbols(locale); } /** * Returns an array of all locales for which the getInstance methods of * this class can return localized instances. * * {@icunote} Unlike java.text.DateFormatSymbols#getAvailableLocales, * this method simply returns the array of Locales available in this * class. ICU does not support DateFormatSymbolsProvider introduced in * Java 6 or its equivalent implementation for now. * * @return An array of Locales for which localized * DateFormatSymbols instances are available. * @stable ICU 3.8 */ public static Locale[] getAvailableLocales() { return ICUResourceBundle.getAvailableLocales(); } /** * {@icu} Returns an array of all locales for which the getInstance * methods of this class can return localized instances. * * {@icunote} Unlike java.text.DateFormatSymbols#getAvailableLocales, * this method simply returns the array of ULocales available in this * class. ICU does not support DateFormatSymbolsProvider introduced in * Java 6 or its equivalent implementation for now. * * @return An array of ULocales for which localized * DateFormatSymbols instances are available. * @draft ICU 3.8 (retain) * @provisional This API might change or be removed in a future release. */ public static ULocale[] getAvailableULocales() { return ICUResourceBundle.getAvailableULocales(); } /** * Era strings. For example: "AD" and "BC". An array of 2 strings, * indexed by Calendar.BC and Calendar.AD. * @serial */ String eras[] = null; /** * Era name strings. For example: "Anno Domini" and "Before Christ". An array of 2 strings, * indexed by Calendar.BC and Calendar.AD. * @serial */ String eraNames[] = null; /** * Narrow era names. For example: "A" and "B". An array of 2 strings, * indexed by Calendar.BC and Calendar.AD. * @serial */ String narrowEras[] = null; /** * Month strings. For example: "January", "February", etc. An array * of 13 strings (some calendars have 13 months), indexed by * Calendar.JANUARY, Calendar.FEBRUARY, etc. * @serial */ String months[] = null; /** * Short month strings. For example: "Jan", "Feb", etc. An array of * 13 strings (some calendars have 13 months), indexed by * Calendar.JANUARY, Calendar.FEBRUARY, etc. * @serial */ String shortMonths[] = null; /** * Narrow month strings. For example: "J", "F", etc. An array of * 13 strings (some calendars have 13 months), indexed by * Calendar.JANUARY, Calendar.FEBRUARY, etc. * @serial */ String narrowMonths[] = null; /** * Standalone month strings. For example: "January", "February", etc. An array * of 13 strings (some calendars have 13 months), indexed by * Calendar.JANUARY, Calendar.FEBRUARY, etc. * @serial */ String standaloneMonths[] = null; /** * Standalone short month strings. For example: "Jan", "Feb", etc. An array of * 13 strings (some calendars have 13 months), indexed by * Calendar.JANUARY, Calendar.FEBRUARY, etc. * @serial */ String standaloneShortMonths[] = null; /** * Standalone narrow month strings. For example: "J", "F", etc. An array of * 13 strings (some calendars have 13 months), indexed by * Calendar.JANUARY, Calendar.FEBRUARY, etc. * @serial */ String standaloneNarrowMonths[] = null; /** * Weekday strings. For example: "Sunday", "Monday", etc. An array * of 8 strings, indexed by Calendar.SUNDAY, * Calendar.MONDAY, etc. * The element weekdays[0] is ignored. * @serial */ String weekdays[] = null; /** * Short weekday strings. For example: "Sun", "Mon", etc. An array * of 8 strings, indexed by Calendar.SUNDAY, * Calendar.MONDAY, etc. * The element shortWeekdays[0] is ignored. * @serial */ String shortWeekdays[] = null; /** * Narrow weekday strings. For example: "S", "M", etc. An array * of 8 strings, indexed by Calendar.SUNDAY, * Calendar.MONDAY, etc. * The element narrowWeekdays[0] is ignored. * @serial */ String narrowWeekdays[] = null; /** * Standalone weekday strings. For example: "Sunday", "Monday", etc. An array * of 8 strings, indexed by Calendar.SUNDAY, * Calendar.MONDAY, etc. * The element standaloneWeekdays[0] is ignored. * @serial */ String standaloneWeekdays[] = null; /** * Standalone short weekday strings. For example: "Sun", "Mon", etc. An array * of 8 strings, indexed by Calendar.SUNDAY, * Calendar.MONDAY, etc. * The element standaloneShortWeekdays[0] is ignored. * @serial */ String standaloneShortWeekdays[] = null; /** * Standalone narrow weekday strings. For example: "S", "M", etc. An array * of 8 strings, indexed by Calendar.SUNDAY, * Calendar.MONDAY, etc. * The element standaloneNarrowWeekdays[0] is ignored. * @serial */ String standaloneNarrowWeekdays[] = null; /** * AM and PM strings. For example: "AM" and "PM". An array of * 2 strings, indexed by Calendar.AM and * Calendar.PM. * @serial */ String ampms[] = null; /** * Abbreviated quarter names. For example: "Q1", "Q2", "Q3", "Q4". An array * of 4 strings indexed by the month divided by 3. * @serial */ String shortQuarters[] = null; /** * Full quarter names. For example: "1st Quarter", "2nd Quarter", "3rd Quarter", * "4th Quarter". An array of 4 strings, indexed by the month divided by 3. * @serial */ String quarters[] = null; /** * Standalone abbreviated quarter names. For example: "Q1", "Q2", "Q3", "Q4". An array * of 4 strings indexed by the month divided by 3. * @serial */ String standaloneShortQuarters[] = null; /** * Standalone full quarter names. For example: "1st Quarter", "2nd Quarter", "3rd Quarter", * "4th Quarter". An array of 4 strings, indexed by the month divided by 3. * @serial */ String standaloneQuarters[] = null; /** * Pattern string used for localized time zone GMT format. For example, "GMT{0}" * @serial */ String gmtFormat = null; /** * Pattern strings used for formatting zone offset in a localized time zone GMT string. * This is 2x2 String array holding followings * [0][0] Negative H + m + s * [0][1] Negative H + m * [1][0] Positive H + m + s * [1][1] Positive H + m * @serial */ String gmtHourFormats[][] = null; /** * Localized names of time zones in this locale. This is a * two-dimensional array of strings of size n by m, * where m is at least 5 and up to 7. Each of the n rows is an * entry containing the localized names for a single TimeZone. * Each such row contains (with i ranging from * 0..n-1): *