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
This commit is contained in:
Fredrik Roubert 2015-02-13 18:20:21 +00:00
parent e567f4ec73
commit 9aadd6b1e9
6 changed files with 65 additions and 24 deletions

View file

@ -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

View file

@ -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

View file

@ -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<String> data = new ArrayList<String>(3);

View file

@ -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, Comparable<Ca
*/
public static final int IS_LEAP_MONTH = 22;
/**
* Field number for related year.
* TODO: http://bugs.icu-project.org/trac/ticket/10761
* @internal
* @deprecated This API is ICU internal only.
*/
@Deprecated
public static final int RELATED_YEAR = 23;
/**
* Field number for <code>get</code> and <code>set</code> separating
* <code>HOUR</code>, <code>MINUTE</code> and <code>SECOND</code>.
@ -961,14 +970,14 @@ public abstract class Calendar implements Serializable, Cloneable, Comparable<Ca
* @deprecated This API is ICU internal only.
*/
@Deprecated
public static final int TIME_SEPARATOR = 23;
public static final int TIME_SEPARATOR = 24;
/**
* The number of fields defined by this class. Subclasses may define
* addition fields starting with this number.
* @stable ICU 2.0
*/
protected static final int BASE_FIELD_COUNT = 24;
protected static final int BASE_FIELD_COUNT = 25;
/**
* The maximum number of fields possible. Subclasses must not define
@ -3010,6 +3019,9 @@ public abstract class Calendar implements Serializable, Cloneable, Comparable<Ca
case JULIAN_DAY:
set(field, internalGet(field) + amount);
return;
case RELATED_YEAR:
// Ignore.
break;
case TIME_SEPARATOR:
// Ignore.
break;
@ -3182,6 +3194,10 @@ public abstract class Calendar implements Serializable, Cloneable, Comparable<Ca
keepWallTimeInvariant = false;
break;
case RELATED_YEAR:
// Ignore.
break;
case TIME_SEPARATOR:
// Ignore.
break;
@ -4170,6 +4186,7 @@ public abstract class Calendar implements Serializable, Cloneable, Comparable<Ca
{ -0x7F000000, -0x7F000000, 0x7F000000, 0x7F000000 }, // JULIAN_DAY
{ 0, 0, 24*ONE_HOUR-1, 24*ONE_HOUR-1 }, // MILLISECONDS_IN_DAY
{ 0, 0, 1, 1 }, // IS_LEAP_MONTH
{/* */}, // RELATED_YEAR
{ Character.MIN_VALUE, Character.MIN_VALUE, Character.MAX_VALUE, Character.MAX_VALUE }, // TIME_SEPARATOR
};

View file

@ -1,5 +1,5 @@
/*
* Copyright (C) 1996-2014, International Business Machines
* Copyright (C) 1996-2015, International Business Machines
* Corporation and others. All Rights Reserved.
*/
@ -278,6 +278,7 @@ public class GregorianCalendar extends Calendar {
{/* */}, // JULIAN_DAY
{/* */}, // MILLISECONDS_IN_DAY
{/* */}, // IS_LEAP_MONTH
{ 1, 1, 5828963, 5838270 }, // RELATED_YEAR
{/* */}, // TIME_SEPARATOR
};

View file

@ -1,7 +1,7 @@
/*
*******************************************************************************
* Copyright (C) 2001-2014, International Business Machines Corporation and *
* others. All Rights Reserved. *
* Copyright (C) 2001-2015, International Business Machines Corporation and
* others. All Rights Reserved.
*******************************************************************************
*/
@ -348,22 +348,22 @@ public class DateFormatTest extends com.ibm.icu.dev.test.TestFmwk {
"", "1997", "August", "13", "", "", "34", "12", "", "Wednesday",
"", "", "", "", "PM", "2", "", "Pacific Daylight Time", "", "",
"", "", "", "", "", "", "", "", "", "",
"", "", "", "", ":",
"", "", "", "", "", ":",
"", "1997", "ao\u00FBt", "13", "", "14", "34", "12", "", "mercredi",
"", "", "", "", "", "", "", "heure d\u2019\u00E9t\u00E9 du Pacifique", "", "",
"", "", "", "", "", "", "", "", "", "",
"", "", "", "", ":",
"", "", "", "", "", ":",
"AD", "1997", "8", "13", "14", "14", "34", "12", "5", "Wed",
"225", "2", "33", "3", "PM", "2", "2", "PDT", "1997", "4",
"1997", "2450674", "52452513", "-0700", "PT", "4", "8", "3", "3", "uslax",
"1997", "GMT-7", "-07", "-07", ":",
"1997", "GMT-7", "-07", "-07", "0", ":",
"Anno Domini", "1997", "August", "0013", "0014", "0014", "0034", "0012", "5130", "Wednesday",
"0225", "0002", "0033", "0003", "PM", "0002", "0002", "Pacific Daylight Time", "1997", "Wednesday",
"1997", "2450674", "52452513", "GMT-07:00", "Pacific Time", "Wednesday", "August", "3rd quarter", "3rd quarter", "Los Angeles Time",
"1997", "GMT-07:00", "-0700", "-0700", ":",
"1997", "GMT-07:00", "-0700", "-0700", "0000", ":",
};
assertTrue("data size", EXPECTED.length == COUNT * DateFormat.FIELD_COUNT);
@ -466,7 +466,7 @@ public class DateFormatTest extends com.ibm.icu.dev.test.TestFmwk {
/**
* This MUST be kept in sync with DateFormatSymbols.patternChars.
*/
static final String PATTERN_CHARS = "GyMdkHmsSEDFwWahKzYeugAZvcLQqVUOXx:";
static final String PATTERN_CHARS = "GyMdkHmsSEDFwWahKzYeugAZvcLQqVUOXxr:";
/**
* A list of the DateFormat.Field.
@ -507,6 +507,7 @@ public class DateFormatTest extends com.ibm.icu.dev.test.TestFmwk {
DateFormat.Field.TIME_ZONE, // O
DateFormat.Field.TIME_ZONE, // X
DateFormat.Field.TIME_ZONE, // x
DateFormat.Field.RELATED_YEAR, // r
DateFormat.Field.TIME_SEPARATOR,// :
};
@ -549,6 +550,7 @@ public class DateFormatTest extends com.ibm.icu.dev.test.TestFmwk {
"TIMEZONE_LOCALIZED_GMT_OFFSET_FIELD",
"TIMEZONE_ISO_FIELD",
"TIMEZONE_ISO_LOCAL_FIELD",
"RELATED_YEAR",
"TIME_SEPARATOR",
};