Index: ChangeLog =================================================================== RCS file: /cvsroot/classpath/classpath/ChangeLog,v retrieving revision 1.2386.2.64 diff -u -3 -p -u -r1.2386.2.64 ChangeLog --- ChangeLog 22 Jan 2005 02:20:00 -0000 1.2386.2.64 +++ ChangeLog 23 Jan 2005 02:41:26 -0000 @@ -1,3 +1,32 @@ +2005-01-23 Andrew John Hughes
+ + * gnu/java/locale/LocaleInformation.java: + Extended localPatternChars string to match root.xml. + * gnu/java/locale/LocaleInformation_en.java: + Removed invalid localPatternChars string. + * gnu/java/locale/LocaleInformation_nl.java: + Likewise. + * java/text/DateFormat.java: + Documented pattern character offset constants and + added new ones. + (Field): Added new static fields for new pattern chars. + * java/text/SimpleDateFormat.java: + (CompiledField): Changed name of FieldSizePair class + to CompiledField after adding the character as an + attribute. Changed fields to private and added + accessors to give encapsulation. + (CompiledField.CompiledField(int,int,char)): Extended + with character field. + (CompiledField.getField()): New accessor method. + (CompiledField.getSize()): New acceessor method. + (CompiledField.getCharacter()): New accessor method. + (CompiledField.toString()): Added primarily for debugging. + (standardChars): Now uses extended 24 character sequence. + (compileFormat(String)): Changed to use CompiledField. + (formatWithAttribute(java.util.Date, gnu.java.text.FormatBuffer, + java.text.FieldPosition)): Changed to use CompiledField. + New handler for RFC 822 timezones added. + 2005-01-22 Andrew John Hughes * java/awt/Checkbox.java: Index: gnu/java/locale/LocaleInformation.java =================================================================== RCS file: /cvsroot/classpath/classpath/gnu/java/locale/LocaleInformation.java,v retrieving revision 1.4.2.1 diff -u -3 -p -u -r1.4.2.1 LocaleInformation.java --- gnu/java/locale/LocaleInformation.java 16 Jan 2005 15:15:01 -0000 1.4.2.1 +++ gnu/java/locale/LocaleInformation.java 23 Jan 2005 02:41:26 -0000 @@ -113,7 +113,7 @@ public class LocaleInformation extends L private static final Object[][] contents = { - { "localPatternChars", "GyMdkHmsSEDFwWahKz" }, + { "localPatternChars", "GyMdkHmsSEDFwWahKzYeugAZ" }, { "currencySymbols", currencySymbols }, { "decimalSeparator", "." }, { "groupingSeparator", "," }, Index: gnu/java/locale/LocaleInformation_en.java =================================================================== RCS file: /cvsroot/classpath/classpath/gnu/java/locale/LocaleInformation_en.java,v retrieving revision 1.18.2.1 diff -u -3 -p -u -r1.18.2.1 LocaleInformation_en.java --- gnu/java/locale/LocaleInformation_en.java 16 Jan 2005 15:15:03 -0000 1.18.2.1 +++ gnu/java/locale/LocaleInformation_en.java 23 Jan 2005 02:41:27 -0000 @@ -241,7 +241,6 @@ public class LocaleInformation_en extend { "eras", eras }, { "shortDateFormat", "M/d/yy" }, { "mediumDateFormat", "MMM d, yyyy" }, - { "localPatternChars", "GyMdkHmsSEDFwWahKz" }, { "longDateFormat", "MMMM d, yyyy" }, { "fullDateFormat", "EEEE, MMMM d, yyyy" }, { "shortTimeFormat", "h:mm a" }, Index: gnu/java/locale/LocaleInformation_nl.java =================================================================== RCS file: /cvsroot/classpath/classpath/gnu/java/locale/LocaleInformation_nl.java,v retrieving revision 1.8.2.1 diff -u -3 -p -u -r1.8.2.1 LocaleInformation_nl.java --- gnu/java/locale/LocaleInformation_nl.java 16 Jan 2005 15:15:05 -0000 1.8.2.1 +++ gnu/java/locale/LocaleInformation_nl.java 23 Jan 2005 02:41:27 -0000 @@ -224,7 +224,6 @@ public class LocaleInformation_nl extend private static final Object[][] contents = { { "collation_rules", collation_rules }, - { "localPatternChars", "GyMdhHmsSEDFwWakKz" }, { "decimalSeparator", "," }, { "groupingSeparator", "." }, { "currenciesDisplayName", currenciesDisplayName }, Index: java/text/DateFormat.java =================================================================== RCS file: /cvsroot/classpath/classpath/java/text/DateFormat.java,v retrieving revision 1.14.2.3 diff -u -3 -p -u -r1.14.2.3 DateFormat.java --- java/text/DateFormat.java 16 Jan 2005 15:15:12 -0000 1.14.2.3 +++ java/text/DateFormat.java 23 Jan 2005 02:41:28 -0000 @@ -70,29 +70,221 @@ public abstract class DateFormat extends /* These constants need to have these exact values. They * correspond to index positions within the localPatternChars - * string for a given locale. For example, the US locale uses - * the string "GyMdkHmsSEDFwWahKz", where 'G' is the character - * for era, 'y' for year, and so on down to 'z' for time zone. - */ + * string for a given locale. Each locale may specify its + * own character for a particular field, but the position + * of these characters must correspond to an appropriate field + * number (as listed below), in order for their meaning to + * be determined. For example, the US locale uses + * the string "GyMdkHmsSEDFwWahKzYeugAZ", where 'G' is the character + * for era, 'y' for year, and so on down to 'Z' for time zone. + */ + /** + * Represents the position of the era + * pattern character in the array of + * localized pattern characters. + * For example, 'AD' is an era used + * in the Gregorian calendar system. + * In the U.S. locale, this is 'G'. + */ public static final int ERA_FIELD = 0; + /** + * Represents the position of the year + * pattern character in the array of + * localized pattern characters. + * In the U.S. locale, this is 'y'. + */ public static final int YEAR_FIELD = 1; + /** + * Represents the position of the month + * pattern character in the array of + * localized pattern characters. + * In the U.S. locale, this is 'M'. + */ public static final int MONTH_FIELD = 2; + /** + * Represents the position of the date + * or day of the month pattern character + * in the array of localized pattern + * characters. In the U.S. locale, + * this is 'd'. + */ public static final int DATE_FIELD = 3; + /** + * Represents the position of the 24 + * hour pattern character in the array of + * localized pattern characters. + * In the U.S. locale, this is 'k'. + * This field numbers hours from 1 to 24. + */ public static final int HOUR_OF_DAY1_FIELD = 4; + /** + * Represents the position of the 24 + * hour pattern character in the array of + * localized pattern characters. + * In the U.S. locale, this is 'H'. + * This field numbers hours from 0 to 23. + */ public static final int HOUR_OF_DAY0_FIELD = 5; + /** + * Represents the position of the minute + * pattern character in the array of + * localized pattern characters. + * In the U.S. locale, this is 'm'. + */ public static final int MINUTE_FIELD = 6; + /** + * Represents the position of the second + * pattern character in the array of + * localized pattern characters. + * In the U.S. locale, this is 's'. + */ public static final int SECOND_FIELD = 7; + /** + * Represents the position of the millisecond + * pattern character in the array of + * localized pattern characters. + * In the U.S. locale, this is 'S'. + */ public static final int MILLISECOND_FIELD = 8; + /** + * Represents the position of the day of the + * week pattern character in the array of + * localized pattern characters. + * In the U.S. locale, this is 'E'. + */ public static final int DAY_OF_WEEK_FIELD = 9; + /** + * Represents the position of the day of the + * year pattern character in the array of + * localized pattern characters. + * In the U.S. locale, this is 'D'. + */ public static final int DAY_OF_YEAR_FIELD = 10; + /** + * Represents the position of the day of the + * week in the month pattern character in the + * array of localized pattern characters. + * In the U.S. locale, this is 'F'. + */ public static final int DAY_OF_WEEK_IN_MONTH_FIELD = 11; + /** + * Represents the position of the week of the + * year pattern character in the array of + * localized pattern characters. + * In the U.S. locale, this is 'w'. + */ public static final int WEEK_OF_YEAR_FIELD = 12; + /** + * Represents the position of the week of the + * month pattern character in the array of + * localized pattern characters. + * In the U.S. locale, this is 'W'. + */ public static final int WEEK_OF_MONTH_FIELD = 13; + /** + * Represents the position of the am/pm + * pattern character in the array of + * localized pattern characters. + * In the U.S. locale, this is 'a'. + */ public static final int AM_PM_FIELD = 14; + /** + * Represents the position of the 12 + * hour pattern character in the array of + * localized pattern characters. + * In the U.S. locale, this is 'h'. + * This field numbers hours from 1 to 12. + */ public static final int HOUR1_FIELD = 15; + /** + * Represents the position of the 12 + * hour pattern character in the array of + * localized pattern characters. + * In the U.S. locale, this is 'K'. + * This field numbers hours from 0 to 11. + */ public static final int HOUR0_FIELD = 16; + /** + * Represents the position of the generic + * timezone pattern character in the array of + * localized pattern characters. + * In the U.S. locale, this is 'z'. + */ public static final int TIMEZONE_FIELD = 17; - + /** + * Represents the position of the ISO year + * pattern character in the array of + * localized pattern characters. + * In the U.S. locale, this is 'Y'. + * This is a GNU extension in accordance with + * the CLDR data used. This value may + * differ from the normal year value. + */ + public static final int ISO_YEAR_FIELD = 18; + /** + * Represents the position of the localized + * day of the week pattern character in the + * array of localized pattern characters. + * In the U.S. locale, this is 'e'. + * This is a GNU extension in accordance with + * the CLDR data used. This value only + * differs from the day of the week with + * numeric formatting, in which case the + * locale's first day of the week is used. + */ + public static final int LOCALIZED_DAY_OF_WEEK_FIELD = 19; + /** + * Represents the position of the extended year + * pattern character in the array of + * localized pattern characters. + * In the U.S. locale, this is 'u'. + * This is a GNU extension in accordance with + * the CLDR data used. This value modifies + * the year value, so as to incorporate the era. + * For example, in the Gregorian calendar system, + * the extended year is negative instead of being + * marked as BC. + */ + public static final int EXTENDED_YEAR_FIELD = 20; + /** + * Represents the position of the modified Julian + * day pattern character in the array of + * localized pattern characters. + * In the U.S. locale, this is 'g'. + * This is a GNU extension in accordance with + * the CLDR data used. This value differs + * from the standard Julian day in that days + * are marked from midnight onwards rather than + * noon, and the local time zone affects the value. + * In simple terms, it can be thought of as all + * the date fields represented as a single number. + */ + public static final int MODIFIED_JULIAN_DAY_FIELD = 21; + /** + * Represents the position of the millisecond + * in the day pattern character in the array of + * localized pattern characters. + * In the U.S. locale, this is 'A'. + * This is a GNU extension in accordance with + * the CLDR data used. This value represents + * all the time fields (excluding the time zone) + * numerically, giving the number of milliseconds + * into the day (e.g. 10 in the morning would + * be 10 * 60 * 60 * 1000). Any daylight savings + * offset also affects this value. + */ + public static final int MILLISECOND_IN_DAY_FIELD = 22; + /** + * Represents the position of the RFC822 + * timezone pattern character in the array of + * localized pattern characters. + * In the U.S. locale, this is 'Z'. + * This is a GNU extension in accordance with + * the CLDR data used. The value is the offset + * of the current time from GMT e.g. -0500 would + * be five hours prior to GMT. + */ + public static final int RFC822_TIMEZONE_FIELD = 23; public static class Field extends Format.Field { @@ -136,14 +328,28 @@ public abstract class DateFormat extends = new Field("hour0", Calendar.HOUR); public static final DateFormat.Field TIME_ZONE = new Field("timezone", Calendar.ZONE_OFFSET); - + public static final DateFormat.Field ISO_YEAR + = new Field("iso year", Calendar.YEAR); + public static final DateFormat.Field LOCALIZED_DAY_OF_WEEK + = new Field("localized day of week", Calendar.DAY_OF_WEEK); + public static final DateFormat.Field EXTENDED_YEAR + = new Field("extended year", Calendar.YEAR); + public static final DateFormat.Field MODIFIED_JULIAN_DAY + = new Field("julian day", -1); + public static final DateFormat.Field MILLISECOND_IN_DAY + = new Field("millisecond in day", -1); + public static final DateFormat.Field RFC822_TIME_ZONE + = new Field("rfc822 timezone", Calendar.ZONE_OFFSET); + static final DateFormat.Field[] allFields = { ERA, YEAR, MONTH, DAY_OF_MONTH, HOUR_OF_DAY1, HOUR_OF_DAY0, MINUTE, SECOND, MILLISECOND, DAY_OF_WEEK, DAY_OF_YEAR, DAY_OF_WEEK_IN_MONTH, WEEK_OF_YEAR, WEEK_OF_MONTH, AM_PM, HOUR1, HOUR0, - TIME_ZONE + TIME_ZONE, ISO_YEAR, LOCALIZED_DAY_OF_WEEK, + EXTENDED_YEAR, MODIFIED_JULIAN_DAY, MILLISECOND_IN_DAY, + RFC822_TIME_ZONE }; // For deserialization Index: java/text/SimpleDateFormat.java =================================================================== RCS file: /cvsroot/classpath/classpath/java/text/SimpleDateFormat.java,v retrieving revision 1.28.2.3 diff -u -3 -p -u -r1.28.2.3 SimpleDateFormat.java --- java/text/SimpleDateFormat.java 22 Jan 2005 02:20:02 -0000 1.28.2.3 +++ java/text/SimpleDateFormat.java 23 Jan 2005 02:41:28 -0000 @@ -64,18 +64,93 @@ import java.util.regex.Pattern; */ public class SimpleDateFormat extends DateFormat { - /** A pair class used by SimpleDateFormat as a compiled representation - * of a format string. - */ - private class FieldSizePair - { - public int field; - public int size; + /** + * This class is used bySimpleDateFormat
as a
+ * compiled representation of a format string. The field
+ * ID, size, and character used are stored for each sequence
+ * of pattern characters or invalid characters in the format
+ * pattern.
+ */
+ private class CompiledField
+ {
+ /**
+ * The ID of the field within the local pattern characters,
+ * or -1 if the sequence is invalid.
+ */
+ private int field;
+
+ /**
+ * The size of the character sequence.
+ */
+ private int size;
- /** Constructs a pair with the given field and size values */
- public FieldSizePair(int f, int s) {
+ /**
+ * The character used.
+ */
+ private char character;
+
+ /**
+ * Constructs a compiled field using the
+ * the given field ID, size and character
+ * values.
+ *
+ * @param f the field ID.
+ * @param s the size of the field.
+ * @param c the character used.
+ */
+ public CompiledField(int f, int s, char c) {
field = f;
size = s;
+ character = c;
+ }
+
+ /**
+ * Retrieves the ID of the field relative to
+ * the local pattern characters, or -1 if
+ * the sequence is invalid.
+ */
+ public int getField()
+ {
+ return field;
+ }
+
+ /**
+ * Retrieves the size of the character sequence.
+ */
+ public int getSize()
+ {
+ return size;
+ }
+
+ /**
+ * Retrieves the character used in the sequence.
+ */
+ public char getCharacter()
+ {
+ return character;
+ }
+
+ /**
+ * Returns a String
representation
+ * of the compiled field, primarily for debugging
+ * purposes.
+ *
+ * @return a String
representation.
+ */
+ public String toString()
+ {
+ StringBuilder builder;
+
+ builder = new StringBuilder(getClass().getName());
+ builder.append("[field=");
+ builder.append(field);
+ builder.append(", size=");
+ builder.append(size);
+ builder.append(", character=");
+ builder.append(character);
+ builder.append("]");
+
+ return builder.toString();
}
}
@@ -87,10 +162,10 @@ public class SimpleDateFormat extends Da
private int serialVersionOnStream = 1; // 0 indicates JDK1.1.3 or earlier
private static final long serialVersionUID = 4774881970558875024L;
- // This string is specified in the JCL. We set it here rather than
- // do a DateFormatSymbols(Locale.US).getLocalPatternChars() since
- // someone could theoretically change those values (though unlikely).
- private static final String standardChars = "GyMdkHmsSEDFwWahKzZ";
+ // This string is specified in the root of the CLDR. We set it here
+ // rather than doing a DateFormatSymbols(Locale.US).getLocalPatternChars()
+ // since someone could theoretically change those values (though unlikely).
+ private static final String standardChars = "GyMdkHmsSEDFwWahKzYeugAZ";
private void readObject(ObjectInputStream stream)
throws IOException, ClassNotFoundException
@@ -118,7 +193,7 @@ public class SimpleDateFormat extends Da
char thisChar;
int pos;
int field;
- FieldSizePair current = null;
+ CompiledField current = null;
for (int i=0; i