From 9aadd6b1e9200a0b28677e01a82358c0ed543a22 Mon Sep 17 00:00:00 2001 From: Fredrik Roubert Date: Fri, 13 Feb 2015 18:20:21 +0000 Subject: [PATCH] ICU-11467 Define the 'r' pattern char and the RELATED_YEAR field. For compatibility with ICU4C, the RELATED_YEAR field should be defined as the field preceding the TIME_SEPARATOR field but by mistake support for the TIME_SEPARATOR field has already been implemented in ICU4J without first defining the RELATED_YEAR field. This change therefore reorders the existing TIME_SEPARATOR field and adds definitions (without any underlying implementation) for the 'r' pattern char and the RELATED_YEAR field. R=markus.icu@gmail.com,pedberg@apple.com Review URL: https://codereview.appspot.com/198460043 X-SVN-Rev: 37032 --- .../core/src/com/ibm/icu/text/DateFormat.java | 24 ++++++++++++++++--- .../com/ibm/icu/text/DateFormatSymbols.java | 6 ++--- .../com/ibm/icu/text/SimpleDateFormat.java | 17 +++++++------ .../core/src/com/ibm/icu/util/Calendar.java | 23 +++++++++++++++--- .../com/ibm/icu/util/GregorianCalendar.java | 3 ++- .../icu/dev/test/format/DateFormatTest.java | 16 +++++++------ 6 files changed, 65 insertions(+), 24 deletions(-) diff --git a/icu4j/main/classes/core/src/com/ibm/icu/text/DateFormat.java b/icu4j/main/classes/core/src/com/ibm/icu/text/DateFormat.java index 38624b04c01..b3b3ce1775a 100644 --- a/icu4j/main/classes/core/src/com/ibm/icu/text/DateFormat.java +++ b/icu4j/main/classes/core/src/com/ibm/icu/text/DateFormat.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 1996-2014, International Business Machines + * Copyright (C) 1996-2015, International Business Machines * Corporation and others. All Rights Reserved. */ @@ -436,11 +436,21 @@ public abstract class DateFormat extends UFormat { */ public final static int TIMEZONE_ISO_LOCAL_FIELD = 33; + /** + * {@icu} FieldPosition selector for 'r' field alignment, + * corresponding to the {@link Calendar#RELATED_YEAR} field. + * TODO: http://bugs.icu-project.org/trac/ticket/10761 + * @internal + * @deprecated This API is ICU internal only. + */ + @Deprecated + final static int RELATED_YEAR = 34; + /** * {@icu} FieldPosition selector for ':' field alignment, * corresponding to the {@link Calendar#TIME_SEPARATOR} field. */ - final static int TIME_SEPARATOR = 34; + final static int TIME_SEPARATOR = 35; /** * {@icu} Number of FieldPosition selectors for DateFormat. @@ -448,7 +458,7 @@ public abstract class DateFormat extends UFormat { * @stable ICU 3.0 */ - public final static int FIELD_COUNT = 35; // must == DateFormatSymbols.patternChars.length() + public final static int FIELD_COUNT = 36; // must == DateFormatSymbols.patternChars.length() /** @@ -2348,6 +2358,14 @@ public abstract class DateFormat extends UFormat { */ public static final Field QUARTER = new Field("quarter", -1); + /** + * Constant identifying the related year field. + * @internal + * @deprecated This API is ICU internal only. + */ + @Deprecated + public static final Field RELATED_YEAR = new Field("related year", Calendar.RELATED_YEAR); + /** * Constant identifying the time separator field. * @internal diff --git a/icu4j/main/classes/core/src/com/ibm/icu/text/DateFormatSymbols.java b/icu4j/main/classes/core/src/com/ibm/icu/text/DateFormatSymbols.java index 23c89a2c592..08f52d4fa6d 100644 --- a/icu4j/main/classes/core/src/com/ibm/icu/text/DateFormatSymbols.java +++ b/icu4j/main/classes/core/src/com/ibm/icu/text/DateFormatSymbols.java @@ -1,7 +1,7 @@ /* ******************************************************************************* - * Copyright (C) 1996-2014, International Business Machines Corporation and * - * others. All Rights Reserved. * + * Copyright (C) 1996-2015, International Business Machines Corporation and + * others. All Rights Reserved. ******************************************************************************* */ @@ -584,7 +584,7 @@ public class DateFormatSymbols implements Serializable, Cloneable { * Unlocalized date-time pattern characters. For example: 'y', 'd', etc. * All locales use the same unlocalized pattern characters. */ - static final String patternChars = "GyMdkHmsSEDFwWahKzYeugAZvcLQqVUOXx:"; + static final String patternChars = "GyMdkHmsSEDFwWahKzYeugAZvcLQqVUOXxr:"; /** * Localized date-time pattern characters. For example, a locale may diff --git a/icu4j/main/classes/core/src/com/ibm/icu/text/SimpleDateFormat.java b/icu4j/main/classes/core/src/com/ibm/icu/text/SimpleDateFormat.java index 20dc192fbb3..29da14fbdbf 100644 --- a/icu4j/main/classes/core/src/com/ibm/icu/text/SimpleDateFormat.java +++ b/icu4j/main/classes/core/src/com/ibm/icu/text/SimpleDateFormat.java @@ -1,7 +1,7 @@ /* ******************************************************************************* - * Copyright (C) 1996-2014, International Business Machines Corporation and * - * others. All Rights Reserved. * + * Copyright (C) 1996-2015, International Business Machines Corporation and + * others. All Rights Reserved. ******************************************************************************* */ @@ -769,7 +769,7 @@ public class SimpleDateFormat extends DateFormat { // ` a b c d e f g h i j k l m n o -1, 40, -1, 30, 30, 30, -1, 0, 50, -1, -1, 50, -1, 60, -1, -1, // p q r s t u v w x y z { | } ~ - -1, 20, -1, 70, -1, 10, 0, 20, 0, 10, 0, -1, -1, -1, -1, -1, + -1, 20, 10, 70, -1, 10, 0, 20, 0, 10, 0, -1, -1, -1, -1, -1, }; /** @@ -1362,7 +1362,7 @@ public class SimpleDateFormat extends DateFormat { // ! " # $ % & ' ( ) * + , - . / -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 0 1 2 3 4 5 6 7 8 9 : ; < = > ? - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 34, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 35, -1, -1, -1, -1, -1, // @ A B C D E F G H I J K L M N O -1, 22, -1, -1, 10, 9, 11, 0, 5, -1, -1, 16, 26, 2, -1, 31, // P Q R S T U V W X Y Z [ \ ] ^ _ @@ -1370,7 +1370,7 @@ public class SimpleDateFormat extends DateFormat { // ` a b c d e f g h i j k l m n o -1, 14, -1, 25, 3, 19, -1, 21, 15, -1, -1, 4, -1, 6, -1, -1, // p q r s t u v w x y z { | } ~ - -1, 28, -1, 7, -1, 20, 24, 12, 33, 1, 17, -1, -1, -1, -1, -1, + -1, 28, 34, 7, -1, 20, 24, 12, 33, 1, 17, -1, -1, -1, -1, -1, }; private static int getIndexFromChar(char ch) { @@ -1396,6 +1396,7 @@ public class SimpleDateFormat extends DateFormat { /*U*/ Calendar.YEAR, /*O*/ Calendar.ZONE_OFFSET, /*Xx*/ Calendar.ZONE_OFFSET, Calendar.ZONE_OFFSET, + /*r*/ Calendar.RELATED_YEAR, /*:*/ Calendar.TIME_SEPARATOR, }; @@ -1417,6 +1418,7 @@ public class SimpleDateFormat extends DateFormat { /*U*/ DateFormat.YEAR_NAME_FIELD, /*O*/ DateFormat.TIMEZONE_LOCALIZED_GMT_OFFSET_FIELD, /*Xx*/ DateFormat.TIMEZONE_ISO_FIELD, DateFormat.TIMEZONE_ISO_LOCAL_FIELD, + /*r*/ DateFormat.RELATED_YEAR, /*:*/ DateFormat.TIME_SEPARATOR, }; @@ -1438,6 +1440,7 @@ public class SimpleDateFormat extends DateFormat { /*U*/ DateFormat.Field.YEAR, /*O*/ DateFormat.Field.TIME_ZONE, /*Xx*/ DateFormat.Field.TIME_ZONE, DateFormat.Field.TIME_ZONE, + /*r*/ DateFormat.Field.RELATED_YEAR, /*:*/ DateFormat.Field.TIME_SEPARATOR, }; @@ -1833,7 +1836,7 @@ public class SimpleDateFormat extends DateFormat { zeroPaddingNumber(currentNumberFormat,buf, (value/3)+1, count, maxIntCount); } break; - case 34: // ':' - TIME SEPARATOR + case 35: // ':' - TIME SEPARATOR buf.append(formatData.getTimeSeparatorString()); break; default: @@ -3291,7 +3294,7 @@ public class SimpleDateFormat extends DateFormat { return newStart; } - case 34: + case 35: { // Try matching a time separator. ArrayList data = new ArrayList(3); diff --git a/icu4j/main/classes/core/src/com/ibm/icu/util/Calendar.java b/icu4j/main/classes/core/src/com/ibm/icu/util/Calendar.java index a9a7e651305..f9aaf9f3570 100644 --- a/icu4j/main/classes/core/src/com/ibm/icu/util/Calendar.java +++ b/icu4j/main/classes/core/src/com/ibm/icu/util/Calendar.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 1996-2014, International Business Machines + * Copyright (C) 1996-2015, International Business Machines * Corporation and others. All Rights Reserved. */ @@ -950,6 +950,15 @@ public abstract class Calendar implements Serializable, Cloneable, Comparableget and set separating * HOUR, MINUTE and SECOND. @@ -961,14 +970,14 @@ public abstract class Calendar implements Serializable, Cloneable, Comparable