ICU-6157 Consolidated skeleton pattern definitions. Cleaned up Javadoc comments for new APIs. Fix Java 1.3/Foundation 1.0 env issues and etc.

X-SVN-Rev: 24070
This commit is contained in:
Yoshito Umaoka 2008-05-29 18:37:14 +00:00
parent 8bcaa88f1e
commit 2fe984e3ce
9 changed files with 424 additions and 854 deletions

1
.gitattributes vendored
View file

@ -216,7 +216,6 @@ icu4j/src/com/ibm/icu/dev/test/duration/testdata/testdata_zh_Hans_SG.txt -text
icu4j/src/com/ibm/icu/dev/test/duration/testdata/testdata_zh_Hant.txt -text
icu4j/src/com/ibm/icu/dev/test/duration/testdata/testdata_zh_Hant_HK.txt -text
icu4j/src/com/ibm/icu/dev/test/format/DataDrivenFormatTest.java -text
icu4j/src/com/ibm/icu/dev/test/format/DateIntervalFormatTest.java -text
icu4j/src/com/ibm/icu/dev/test/perf/data/collation/TestNames_Asian.txt -text
icu4j/src/com/ibm/icu/dev/test/perf/data/collation/TestNames_Chinese.txt -text
icu4j/src/com/ibm/icu/dev/test/perf/data/collation/TestNames_Japanese.txt -text

View file

@ -42,6 +42,7 @@ src/com/ibm/icu/dev/test/collator/TestAll.java
src/com/ibm/icu/dev/test/duration/ICUDurationTest.java
src/com/ibm/icu/dev/test/format/BigNumberFormatTest.java
src/com/ibm/icu/dev/test/format/DateFormatTest.java
src/com/ibm/icu/dev/test/format/DateIntervalFormatTest.java
src/com/ibm/icu/dev/test/format/DateTimeGeneratorTest.java
src/com/ibm/icu/dev/test/format/IntlTestDecimalFormatAPIC.java
src/com/ibm/icu/dev/test/format/IntlTestNumberFormatAPI.java

View file

@ -54,28 +54,28 @@ public class DateFormatTest extends com.ibm.icu.dev.test.TestFmwk {
*/
public void TestPatterns() {
final String[][] EXPECTED = {
{DateFormat.MINUTE_SECOND, "mss", "en", "m:ss"},
{DateFormat.HOUR_MINUTE, "Hmm", "en", "H:mm"},
{DateFormat.HOUR_MINUTE_SECOND, "Hmmss","en","H:mm:ss"},
{DateFormat.HOUR12_MINUTE, "hmma","en","h:mm a"},
{DateFormat.HOUR12_MINUTE_SECOND, "hmmssa","en","h:mm:ss a"},
{DateFormat.MINUTE_SECOND, "ms", "en", "m:s"},
{DateFormat.HOUR24_MINUTE, "Hm", "en", "H:m"},
{DateFormat.HOUR24_MINUTE_SECOND, "Hms","en","H:m:s"},
{DateFormat.HOUR_MINUTE, "hm","en","h:m a"},
{DateFormat.HOUR_MINUTE_SECOND, "hms","en","h:m:s a"},
{DateFormat.DAY, "d","en","d"},
{DateFormat.MONTH, "LLLL","en","LLLL"},
{DateFormat.ABBR_MONTH, "LLL","en","LLL"},
{DateFormat.YEAR, "yyyy","en","yyyy"},
{DateFormat.STANDALONE_MONTH, "LLLL","en","LLLL"},
{DateFormat.ABBR_STANDALONE_MONTH, "LLL","en","LLL"},
{DateFormat.YEAR, "y","en","y"},
{DateFormat.MONTH_DAY, "MMMMd","en","MMMM d"},
{DateFormat.ABBR_MONTH_DAY, "MMMd","en","MMM d"},
{DateFormat.NUM_MONTH_DAY, "Md","en","M/d"},
{DateFormat.MONTH_DAY_WEEKDAY, "MMMMdE","en","E, MMMM d"},
{DateFormat.ABBR_MONTH_DAY_WEEKDAY, "MMMdE","en","E, MMM d"},
{DateFormat.NUM_MONTH_DAY_WEEKDAY, "MdE","en","E, M/d"},
{DateFormat.YEAR_MONTH, "yyyyMMMM","en","MMMM yyyy"},
{DateFormat.YEAR_ABBR_MONTH, "yyyyMMM","en","MMM yyyy"},
{DateFormat.YEAR_NUM_MONTH, "yyyyM","en","M/yyyy"},
{DateFormat.YEAR_ABBR_MONTH_DAY_WEEKDAY, "yyyyMMMdEEE", "en", "EEE, MMM d, yyyy"},
{DateFormat.YEAR_NUM_MONTH_DAY_WEEKDAY, "yyyyMdEEE", "en", "EEE, M/d/yyyy"},
{DateFormat.YEAR_QUARTER, "yyyyQQQ", "en", "QQQ yyyy"},
{DateFormat.YEAR_ABBR_QUARTER, "yyyyQ", "en", "Q yyyy"}
{DateFormat.MONTH_WEEKDAY_DAY, "MMMMEEEEd","en","EEEE, MMMM d"},
{DateFormat.ABBR_MONTH_WEEKDAY_DAY, "MMMEd","en","E, MMM d"},
{DateFormat.NUM_MONTH_WEEKDAY_DAY, "MEd","en","E, M/d"},
{DateFormat.YEAR_MONTH, "yMMMM","en","MMMM y"},
{DateFormat.YEAR_ABBR_MONTH, "yMMM","en","MMM y"},
{DateFormat.YEAR_NUM_MONTH, "yM","en","M/y"},
{DateFormat.YEAR_ABBR_MONTH_WEEKDAY_DAY, "yMMMEd", "en", "E, MMM d, y"},
{DateFormat.YEAR_NUM_MONTH_WEEKDAY_DAY, "yMEd", "en", "E, M/d/y"},
{DateFormat.YEAR_QUARTER, "yQQQ", "en", "QQQ y"},
{DateFormat.YEAR_ABBR_QUARTER, "yQ", "en", "Q y"}
};
for (int i = 0; i < EXPECTED.length; i++) {

View file

@ -1,4 +1,6 @@
//##header J2SE15
//#if defined(FOUNDATION10) || defined(J2SE13)
//#else
/*
*******************************************************************************
* Copyright (C) 2001-2008, International Business Machines Corporation and *
@ -13,40 +15,44 @@
package com.ibm.icu.dev.test.format;
//import java.io.FileOutputStream;
//import java.io.IOException;
//import java.io.UnsupportedEncodingException;
//import java.io.OutputStreamWriter;
//import java.text.FieldPosition;
//import java.text.ParseException;
//import java.util.Date;
//import java.util.Locale;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.FileNotFoundException;
import java.io.UnsupportedEncodingException;
import java.io.OutputStreamWriter;
import java.text.FieldPosition;
import java.text.ParseException;
import java.util.Date;
import java.util.Locale;
//import com.ibm.icu.text.DateFormat;
//import com.ibm.icu.text.SimpleDateFormat;
//import com.ibm.icu.util.Calendar;
//import com.ibm.icu.util.DateInterval;
//import com.ibm.icu.text.DateIntervalInfo;
//import com.ibm.icu.text.DateIntervalFormat;
import com.ibm.icu.text.DateFormat;
import com.ibm.icu.text.SimpleDateFormat;
import com.ibm.icu.util.Calendar;
import com.ibm.icu.util.DateInterval;
import com.ibm.icu.text.DateIntervalInfo;
import com.ibm.icu.text.DateIntervalFormat;
public class DateIntervalFormatTest extends com.ibm.icu.dev.test.TestFmwk {
public static boolean DEBUG = true;
public static boolean DEBUG = false;
public static void main(String[] args) throws Exception {
new DateIntervalFormatTest().run(args);
}
/**
* General parse/format tests. Add test cases as needed.
*/
public void TestFormat() {
// TODO - !!!! FIX THE TEST POROBLEM !!!!
// This test is not working well now. Skip.
if (true) return;
// test data.
// The 1st is the format pattern,
// Next are pairs in which the 1st in the pair is the earlier date
// and the 2nd in the pair is the later date
/*
String[] DATA = {
"yyyy MM dd HH:mm:ss",
"2007 10 10 10:10:10", "2008 10 10 10:10:10",
@ -56,8 +62,8 @@ public class DateIntervalFormatTest extends com.ibm.icu.dev.test.TestFmwk {
"2007 01 10 10:00:10", "2007 01 10 10:20:10",
"2007 01 10 10:10:10", "2007 01 10 10:10:20",
};
String[][] testLocale = {
{"en", "", ""},
{"zh", "", ""},
@ -99,11 +105,11 @@ public class DateIntervalFormatTest extends com.ibm.icu.dev.test.TestFmwk {
{"uk", "", ""},
{"hi", "", ""},
};
*/
/* TODO: uncomment
* comment out temporarily, need to un-comment when CLDR data
* is ready
*/
int localeIndex;
for ( localeIndex = 0; localeIndex < testLocale.length; ++localeIndex) {
@ -111,14 +117,12 @@ public class DateIntervalFormatTest extends com.ibm.icu.dev.test.TestFmwk {
testLocale[localeIndex][1], testLocale[localeIndex][2]),
testLocale[localeIndex][0]+testLocale[localeIndex][1]);
}
*/
}
/*
void expect(String[] data, int data_length, Locale loc, String locName) {
String[] formatResults = {
};
// String[] formatResults = {
// };
String[] skeleton = {
"EEEEdMMMMy",
@ -156,15 +160,17 @@ public class DateIntervalFormatTest extends com.ibm.icu.dev.test.TestFmwk {
"dMMMMMy",
"EEEEEdM",
};
int i = 0;
SimpleDateFormat ref = new SimpleDateFormat(data[i++], loc);
try {
OutputStreamWriter osw = new OutputStreamWriter(new FileOutputStream("/home/xji/tmp_work/java.test.res", true), "UTF-8");
//OutputStreamWriter osw = new OutputStreamWriter(new ByteArrayOutputStream(), "UTF-8");
OutputStreamWriter osw = null;
if (DEBUG) {
osw = new OutputStreamWriter(new FileOutputStream("/home/xji/tmp_work/java.test.res", true), "UTF-8");
//osw = new OutputStreamWriter(new ByteArrayOutputStream(), "UTF-8");
}
if ( DEBUG ) {
osw.write("locale: " + locName + "\n");
@ -188,44 +194,11 @@ public class DateIntervalFormatTest extends com.ibm.icu.dev.test.TestFmwk {
}
DateInterval dtitv = new DateInterval(date.getTime(), date_2.getTime());
for ( int style = DateFormat.FULL; style < 4; ++style ) {
DateIntervalFormat dtitvfmt = DateIntervalFormat.getDateIntervalInstance(style, loc);
FieldPosition pos = new FieldPosition(0);
StringBuffer str = new StringBuffer("");
dtitvfmt.format(dtitv, str, pos);
if ( DEBUG ) {
osw.write("date interval, style = " + style + "\n");
osw.write("interval date: " + str + "\n");
}
}
for ( int style = DateFormat.FULL; style < 4; ++style ) {
DateIntervalFormat dtitvfmt = DateIntervalFormat.getTimeIntervalInstance(style, loc);
FieldPosition pos = new FieldPosition(0);
StringBuffer str = new StringBuffer("");
dtitvfmt.format(dtitv, str, pos);
if ( DEBUG ) {
osw.write("time interval, style = " + style + "\n");
osw.write("interval date: " + str + "\n");
}
}
for ( int style = DateFormat.FULL; style < 4; ++style ) {
DateIntervalFormat dtitvfmt = DateIntervalFormat.getDateTimeIntervalInstance(style, style, loc);
FieldPosition pos = new FieldPosition(0);
StringBuffer str = new StringBuffer("");
dtitvfmt.format(dtitv, str, pos);
if ( DEBUG ) {
osw.write("date time interval, style = " + style + "\n");
osw.write("interval date: " + str + "\n");
}
}
for ( int skeletonIndex = 0;
skeletonIndex < skeleton.length;
++skeletonIndex ) {
String oneSkeleton = skeleton[skeletonIndex];
DateIntervalFormat dtitvfmt = DateIntervalFormat.getInstance(oneSkeleton, false, loc);
DateIntervalFormat dtitvfmt = DateIntervalFormat.getInstance(oneSkeleton, loc);
FieldPosition pos = new FieldPosition(0);
StringBuffer str = new StringBuffer("");
dtitvfmt.format(dtitv, str, pos);
@ -241,8 +214,8 @@ public class DateIntervalFormatTest extends com.ibm.icu.dev.test.TestFmwk {
dtitvinf.setIntervalPattern("yMMMd", Calendar.MONTH, "yyyy MMM d - MMM y");
dtitvinf.setIntervalPattern("yMMMd", Calendar.HOUR_OF_DAY, "yyyy MMM d HH:mm - HH:mm");
DateIntervalFormat dtitvfmt = DateIntervalFormat.getInstance(
DateIntervalFormat.YEAR_MONTH_DAY_MEDIUM_FORMAT,
false, loc, dtitvinf);
DateFormat.YEAR_ABBR_MONTH_DAY,
loc, dtitvinf);
FieldPosition pos = new FieldPosition(0);
StringBuffer str = new StringBuffer("");
dtitvfmt.format(dtitv, str, pos);
@ -253,7 +226,7 @@ public class DateIntervalFormatTest extends com.ibm.icu.dev.test.TestFmwk {
// test interval format used by CLDR survey tool
//dtitvfmt = DateIntervalFormat.getEmptyInstance();
dtitvfmt = DateIntervalFormat.getInstance();
dtitvfmt = DateIntervalFormat.getInstance("yMd");
SimpleDateFormat dtfmt = new SimpleDateFormat("yyyy 'year' MMM 'month' dd 'day'", loc);
dtitvfmt.setDateFormat(dtfmt);
dtitvinf = new DateIntervalInfo();
@ -300,9 +273,9 @@ public class DateIntervalFormatTest extends com.ibm.icu.dev.test.TestFmwk {
errln("UTF-8 is not supported\n");
return;
} catch ( IOException e ) {
errln("IOException: " + e);
return;
errln("IOException: " + e);
return;
}
}
*/
}
//#endif

View file

@ -1878,7 +1878,7 @@ public class FormatTests
public Object[] getTestObjects()
{
DateIntervalFormat dateIntervalFormats[] = {
DateIntervalFormat.getInstance("yMMMMEEEEd", false)
DateIntervalFormat.getInstance("yMMMMEEEEd")
};
return dateIntervalFormats;
}

View file

@ -676,40 +676,103 @@ public abstract class DateFormat extends UFormat {
//#if defined(FOUNDATION10) || defined(J2SE13)
//#else
/* Below are pre-defined skeletons
*
* <P>
* A skeleton
* <ul>
* <li>
* 1. only keeps the field pattern letter and ignores all other parts
* in a pattern, such as space, punctuations, and string literals.
* <li>
* 2. hides the order of fields.
* <li>
* 3. might hide a field's pattern letter length.
*
* For those non-digit calendar fields, the pattern letter length is
* important, such as MMM, MMMM, and MMMMM; E and EEEE,
* and the field's pattern letter length is honored.
*
* For the digit calendar fields, such as M or MM, d or dd, yy or yyyy,
* the field pattern length is ignored and the best match, which is
* defined in date time patterns, will be returned without honor
* the field pattern letter length in skeleton.
* </ul>
*/
/**
* Constant for date pattern denoted by the skeleton <code>mss</code>.
* Constant for date pattern denoted by the skeleton <code>ms</code>.
* @draft ICU 4.0
* @provisional This API might change or be removed in a future release.
*/
public static final String MINUTE_SECOND = "mss";
public static final String MINUTE_SECOND = "ms";
/**
* Constant for date pattern denoted by the skeleton <code>Hmm</code>.
* Constant for date pattern denoted by the skeleton <code>Hm</code>.
* @draft ICU 4.0
* @provisional This API might change or be removed in a future release.
*/
public static final String HOUR_MINUTE = "Hmm";
public static final String HOUR24_MINUTE = "Hm";
/**
* Constant for date pattern denoted by the skeleton <code>Hmmss</code>.
* Constant for date pattern denoted by the skeleton <code>Hms</code>.
* @draft ICU 4.0
* @provisional This API might change or be removed in a future release.
*/
public static final String HOUR_MINUTE_SECOND = "Hmmss";
public static final String HOUR24_MINUTE_SECOND = "Hms";
/**
* Constant for date pattern denoted by the skeleton <code>hmma</code>.
* Constant for date pattern denoted by the skeleton <code>hms</code>.
* @draft ICU 4.0
* @provisional This API might change or be removed in a future release.
*/
public static final String HOUR12_MINUTE = "hmma";
public static final String HOUR_MINUTE_SECOND = "hms";
/**
* Constant for date pattern denoted by the skeleton <code>hmmssa</code>.
* Constant for date pattern denoted by the skeleton <code>LLLL</code>.
* @draft ICU 4.0
* @provisional This API might change or be removed in a future release.
*/
public static final String HOUR12_MINUTE_SECOND = "hmmssa";
public static final String STANDALONE_MONTH = "LLLL";
/**
* Constant for date pattern denoted by the skeleton <code>LLL</code>.
* @draft ICU 4.0
* @provisional This API might change or be removed in a future release.
*/
public static final String ABBR_STANDALONE_MONTH = "LLL";
/**
* Constant for date pattern denoted by the skeleton <code>yQQQ</code>.
* @draft ICU 4.0
* @provisional This API might change or be removed in a future release.
*/
public static final String YEAR_QUARTER = "yQQQ";
/**
* Constant for date pattern denoted by the skeleton <code>yQ</code>.
* @draft ICU 4.0
* @provisional This API might change or be removed in a future release.
*/
public static final String YEAR_ABBR_QUARTER = "yQ";
/* Below are skeletons that date interval pre-defined in resource file.
* Users are encouraged to use them in date interval format factory methods.
*/
/**
* Constant for date pattern denoted by the skeleton <code>hm</code>.
* @draft ICU 4.0
* @provisional This API might change or be removed in a future release.
*/
public static final String HOUR_MINUTE = "hm";
/**
* Constant for date pattern denoted by the skeleton <code>y</code>.
* @draft ICU 4.0
* @provisional This API might change or be removed in a future release.
*/
public static final String YEAR = "y";
/**
* Constant for date pattern denoted by the skeleton <code>d</code>.
@ -719,25 +782,53 @@ public abstract class DateFormat extends UFormat {
public static final String DAY = "d";
/**
* Constant for date pattern denoted by the skeleton <code>LLLL</code>.
* Constant for date pattern denoted by the skeleton <code>MEd</code>.
* @draft ICU 4.0
* @provisional This API might change or be removed in a future release.
*/
public static final String MONTH = "LLLL";
public static final String NUM_MONTH_WEEKDAY_DAY = "MEd";
/**
* Constant for date pattern denoted by the skeleton <code>LLL</code>.
* Constant for date pattern denoted by the skeleton <code>yM</code>.
* @draft ICU 4.0
* @provisional This API might change or be removed in a future release.
*/
public static final String ABBR_MONTH = "LLL";
public static final String YEAR_NUM_MONTH = "yM";
/**
* Constant for date pattern denoted by the skeleton <code>yyyy</code>.
* Constant for date pattern denoted by the skeleton <code>Md</code>.
* @draft ICU 4.0
* @provisional This API might change or be removed in a future release.
*/
public static final String YEAR = "yyyy";
public static final String NUM_MONTH_DAY = "Md";
/**
* Constant for date pattern denoted by the skeleton <code>yMEd</code>.
* @draft ICU 4.0
* @provisional This API might change or be removed in a future release.
*/
public static final String YEAR_NUM_MONTH_WEEKDAY_DAY = "yMEd";
/**
* Constant for date pattern denoted by the skeleton <code>MMMEd</code>.
* @draft ICU 4.0
* @provisional This API might change or be removed in a future release.
*/
public static final String ABBR_MONTH_WEEKDAY_DAY = "MMMEd";
/**
* Constant for date pattern denoted by the skeleton <code>yMMMM</code>.
* @draft ICU 4.0
* @provisional This API might change or be removed in a future release.
*/
public static final String YEAR_MONTH = "yMMMM";
/**
* Constant for date pattern denoted by the skeleton <code>yMMM</code>.
* @draft ICU 4.0
* @provisional This API might change or be removed in a future release.
*/
public static final String YEAR_ABBR_MONTH = "yMMM";
/**
* Constant for date pattern denoted by the skeleton <code>MMMMd</code>.
@ -753,83 +844,105 @@ public abstract class DateFormat extends UFormat {
* @provisional This API might change or be removed in a future release.
*/
public static final String ABBR_MONTH_DAY = "MMMd";
/**
* Constant for date pattern denoted by the skeleton <code>MMMMEEEEd</code>.
* @draft ICU 4.0
* @provisional This API might change or be removed in a future release.
*/
public static final String MONTH_WEEKDAY_DAY = "MMMMEEEEd";
/**
* Constant for date pattern denoted by the skeleton <code>Md</code>.
* Constant for date pattern denoted by the skeleton <code>yMMMEd</code>.
* @draft ICU 4.0
* @provisional This API might change or be removed in a future release.
*/
public static final String NUM_MONTH_DAY = "Md";
public static final String YEAR_ABBR_MONTH_WEEKDAY_DAY = "yMMMEd";
/**
* Constant for date pattern denoted by the skeleton <code>MMMMdE</code>.
* Constant for date pattern denoted by the skeleton <code>yMMMMEEEEd</code>.
* @draft ICU 4.0
* @provisional This API might change or be removed in a future release.
*/
public static final String MONTH_DAY_WEEKDAY = "MMMMdE";
public static final String YEAR_MONTH_WEEKDAY_DAY = "yMMMMEEEEd";
/**
* Constant for date pattern denoted by the skeleton <code>MMMdE</code>.
* Constant for date pattern denoted by the skeleton <code>yMMMMd</code>.
* @draft ICU 4.0
* @provisional This API might change or be removed in a future release.
*/
public static final String ABBR_MONTH_DAY_WEEKDAY = "MMMdE";
public static final String YEAR_MONTH_DAY = "yMMMMd";
/**
* Constant for date pattern denoted by the skeleton <code>MdE</code>.
* Constant for date pattern denoted by the skeleton <code>yMMMd</code>.
* @draft ICU 4.0
* @provisional This API might change or be removed in a future release.
*/
public static final String NUM_MONTH_DAY_WEEKDAY = "MdE";
public static final String YEAR_ABBR_MONTH_DAY = "yMMMd";
/**
* Constant for date pattern denoted by the skeleton <code>yyyyMMMM</code>.
* Constant for date pattern denoted by the skeleton <code>yMd</code>.
* @draft ICU 4.0
* @provisional This API might change or be removed in a future release.
*/
public static final String YEAR_MONTH = "yyyyMMMM";
public static final String YEAR_NUM_MONTH_DAY = "yMd";
/**
* Constant for date pattern denoted by the skeleton <code>yyyyMMM</code>.
* Constant for date pattern denoted by the skeleton <code>M</code>.
* @draft ICU 4.0
* @provisional This API might change or be removed in a future release.
*/
public static final String YEAR_ABBR_MONTH = "yyyyMMM";
public static final String NUM_MONTH = "M";
/**
* Constant for date pattern denoted by the skeleton <code>yyyyM</code>.
* Constant for date pattern denoted by the skeleton <code>MMM</code>.
* @draft ICU 4.0
* @provisional This API might change or be removed in a future release.
*/
public static final String YEAR_NUM_MONTH = "yyyyM";
public static final String ABBR_MONTH = "MMM";
/**
* Constant for date pattern denoted by the skeleton <code>yyyyMMMdEEE</code>.
* Constant for date pattern denoted by the skeleton <code>MMMM</code>.
* @draft ICU 4.0
* @provisional This API might change or be removed in a future release.
*/
public static final String YEAR_ABBR_MONTH_DAY_WEEKDAY = "yyyyMMMdEEE";
public static final String MONTH = "MMMM";
/**
* Constant for date pattern denoted by the skeleton <code>yyyyMdEEE</code>.
* Constant for date pattern denoted by the skeleton <code>hmv</code>.
* @draft ICU 4.0
* @provisional This API might change or be removed in a future release.
*/
public static final String YEAR_NUM_MONTH_DAY_WEEKDAY = "yyyyMdEEE";
public static final String HOUR_MINUTE_GENERIC_TZ = "hmv";
/**
* Constant for date pattern denoted by the skeleton <code>yyyyQQQ</code>.
* Constant for date pattern denoted by the skeleton <code>hmz</code>.
* @draft ICU 4.0
* @provisional This API might change or be removed in a future release.
*/
public static final String YEAR_QUARTER = "yyyyQQQ";
public static final String HOUR_MINUTE_TZ = "hmz";
/**
* Constant for date pattern denoted by the skeleton <code>yyyyQ</code>.
* Constant for date pattern denoted by the skeleton <code>h</code>.
* @draft ICU 4.0
* @provisional This API might change or be removed in a future release.
*/
public static final String YEAR_ABBR_QUARTER = "yyyyQ";
public static final String HOUR = "h";
/**
* Constant for date pattern denoted by the skeleton <code>hv</code>.
* @draft ICU 4.0
* @provisional This API might change or be removed in a future release.
*/
public static final String HOUR_GENERIC_TZ = "hv";
/**
* Constant for date pattern denoted by the skeleton <code>hz</code>.
* @draft ICU 4.0
* @provisional This API might change or be removed in a future release.
*/
public static final String HOUR_TZ = "hz";
//#endif
/**
* Gets the time formatter with the default formatting style
@ -1389,44 +1502,6 @@ public abstract class DateFormat extends UFormat {
//#if defined(FOUNDATION10) || defined(J2SE13)
//#else
/**
* Create a date/time formatter from skeleton and a given locale.
*
* Users are encouraged to use the static skeletons
* defined in DateIntervalFormat.
* For example, MONTH_DOW_DAY_LONG_FORMAT, which is "MMMMEEEEd",
* and which means the pattern should have day, month, and day-of-week
* fields, and follow the long date format defined in date time pattern.
* For example, for English, the full pattern should be
* "EEEE, MMMM d".
*
* Temporarily, this is internal API, used by DateIntervalFormat only.
* And there will be a new set of public API for the same purpose coming
* soon. After which, this API will be replaced.
*
* @param skeleton the skeleton on which date format based.
* @param adjustFieldWidth whether adjust the skeleton field width or not.
* It is used for DateTimePatternGenerator to
* adjust field width when get
* full pattern from skeleton.
* @param locale the given locale.
* @return a simple date formatter.
* @draft ICU 4.0
* @provisional This API might change or be removed in a future release.
*/
static final DateFormat getInstance(String skeleton,
boolean adjustFieldWidth,
ULocale locale)
{
DateTimePatternGenerator dtptg =
DateTimePatternGenerator.getInstance(locale);
// TODO (xji): use adjustFieldWidth later
String pattern = dtptg.getBestPattern(skeleton);
SimpleDateFormat dtfmt = new SimpleDateFormat(pattern, locale);
return dtfmt;
}
/**
* Convenience overload
* @draft ICU 4.0
@ -1455,7 +1530,7 @@ public abstract class DateFormat extends UFormat {
*
* @param pattern The pattern that selects the fields to be formatted. (Uses the
* {@link DateTimePatternGenerator}.) This can be {@link DateFormat#ABBR_MONTH},
* {@link DateFormat#MONTH_DAY_WEEKDAY}, etc.
* {@link DateFormat#MONTH_WEEKDAY_DAY}, etc.
*
* @param locale The locale for which the date/time format is desired.
*
@ -1488,7 +1563,7 @@ public abstract class DateFormat extends UFormat {
*
* @param pattern The pattern that selects the fields to be formatted. (Uses the
* {@link DateTimePatternGenerator}.) This can be
* {@link DateFormat#ABBR_MONTH}, {@link DateFormat#MONTH_DAY_WEEKDAY},
* {@link DateFormat#ABBR_MONTH}, {@link DateFormat#MONTH_WEEKDAY_DAY},
* etc.
*
* @param locale The locale for which the date/time format is desired.

File diff suppressed because it is too large Load diff

View file

@ -53,23 +53,6 @@ import com.ibm.icu.util.Freezable;
* </ol>
*
* <P>
* There is a set of pre-defined static skeleton strings.
* The skeletons defined consist of the desired calendar field set
* (for example, DAY, MONTH, YEAR) and the format length (long, medium, short)
* used in date time patterns.
*
* For example, skeleton YEAR_MONTH_MEDIUM_FORMAT consists month and year,
* and it's corresponding full pattern is medium format date pattern.
* So, the skeleton is "MMMy", for English, the full pattern is "MMM yyyy",
* which is the format by removing DATE from medium date format.
*
* For example, skeleton YEAR_MONTH_DOW_DAY_MEDIUM_FORMAT consists day, month,
* year, and day-of-week, and it's corresponding full pattern is the medium
* format date pattern. So, the skeleton is "yMMMEEEd", for English,
* the full pattern is "EEE, MMM d, yyyy", which is the medium date format
* plus day-of-week.
*
* <P>
* The calendar fields we support for interval formatting are:
* year, month, date, day-of-week, am-pm, hour, hour-of-day, and minute.
* Those calendar fields can be defined in the following order:
@ -82,9 +65,10 @@ import com.ibm.icu.util.Freezable;
* and "Feb 20, 2008" is year.
*
* <P>
* There is a set of pre-defined static skeleton strings.
* There are pre-defined interval patterns for those pre-defined skeletons
* in locales' resource files.
* For example, for a skeleton YEAR_MONTH_DAY_MEDIUM_FORMAT, which is "yMMMd",
* For example, for a skeleton YEAR_ABBR_MONTH_DAY, which is "yMMMd",
* in en_US, if the largest different calendar field between date1 and date2
* is "year", the date interval pattern is "MMM d, yyyy - MMM d, yyyy",
* such as "Jan 10, 2007 - Jan 10, 2008".
@ -109,7 +93,7 @@ import com.ibm.icu.util.Freezable;
* the first date in the interval pattern for this locale is earlier date.
* If the fallback format is "{1} - {0}", it means the first date is the
* later date.
* For a paticular interval pattern, the default order can be overriden
* For a particular interval pattern, the default order can be overriden
* by prefixing "latestFirst:" or "earliestFirst:" to the interval pattern.
* For example, if the fallback format is "{0}-{1}",
* but for skeleton "yMMMd", the interval pattern when day is different is
@ -136,17 +120,19 @@ import com.ibm.icu.util.Freezable;
* DAY_OF_WEEK, AM_PM, HOUR, HOUR_OF_DAY, and MINUTE.
* Interval patterns when other calendar fields are different is not supported.
* <P>
* DateIntervalInfo objects are clonable.
* DateIntervalInfo objects are cloneable.
* When clients obtain a DateIntervalInfo object,
* they can feel free to modify it as necessary.
* <P>
* DateIntervalInfo are not expected to be subclassed.
* Data for a calendar is loaded out of resource bundles.
* To ICU 4.0, date interval patterns are only supported in Gregorian calendar.
* To ICU 4.0, date interval patterns are only supported in Gregorian calendar.
*
* @draft ICU 4.0
* @provisional This API might change or be removed in a future release.
**/
public class DateIntervalInfo implements Cloneable, Freezable, Serializable {
public class DateIntervalInfo implements Cloneable, Freezable, Serializable {
/* Save the interval pattern information.
* Interval pattern consists of 2 single date patterns and the separator.
* For example, interval pattern "MMM d - MMM d, yyyy" consists
@ -158,12 +144,18 @@ public class DateIntervalInfo implements Cloneable, Freezable, Serializable {
*/
static final int currentSerialVersion = 1;
/**
* PatternInfo class saves the first and second part of interval pattern,
* and whether the interval pattern is earlier date first.
* @draft ICU 4.0
* @provisional This API might change or be removed in a future release.
*/
public static final class PatternInfo implements Cloneable, Serializable {
static final int currentSerialVersion = 1;
private static final long serialVersionUID = 1;
private final String fIntervalPatternFirstPart;
private final String fIntervalPatternSecondPart;
/**
/*
* Whether the first date in interval pattern is later date or not.
* Fallback format set the default ordering.
* And for a particular interval pattern, the order can be
@ -177,26 +169,51 @@ public class DateIntervalInfo implements Cloneable, Freezable, Serializable {
* the interval format is "10 Feb - 10 Jan, 2007"
*/
private final boolean fFirstDateInPtnIsLaterDate;
/**
* constructor
* @draft ICU 4.0
* @provisional This API might change or be removed in a future release.
*/
public PatternInfo(String firstPart, String secondPart,
boolean firstDateInPtnIsLaterDate) {
fIntervalPatternFirstPart = firstPart;
fIntervalPatternSecondPart = secondPart;
fFirstDateInPtnIsLaterDate = firstDateInPtnIsLaterDate;
}
/**
* accessor
* @draft ICU 4.0
* @provisional This API might change or be removed in a future release.
*/
public String getFirstPart() {
return fIntervalPatternFirstPart;
}
/**
* accessor
* @draft ICU 4.0
* @provisional This API might change or be removed in a future release.
*/
public String getSecondPart() {
return fIntervalPatternSecondPart;
}
/**
* accessor
* @draft ICU 4.0
* @provisional This API might change or be removed in a future release.
*/
public boolean firstDateInPtnIsLaterDate() {
return fFirstDateInPtnIsLaterDate;
}
/**
* Override equals
* @draft ICU 4.0
* @provisional This API might change or be removed in a future release.
*/
public boolean equals(Object a) {
if ( a instanceof PatternInfo ) {
PatternInfo patternInfo = (PatternInfo)a;
@ -207,6 +224,11 @@ public class DateIntervalInfo implements Cloneable, Freezable, Serializable {
return false;
}
/**
* Override hashcode
* @draft ICU 4.0
* @provisional This API might change or be removed in a future release.
*/
public int hashCode() {
return fIntervalPatternFirstPart.hashCode() +
fIntervalPatternSecondPart.hashCode();
@ -258,6 +280,7 @@ public class DateIntervalInfo implements Cloneable, Freezable, Serializable {
* wants to create their own interval patterns and use them to create
* date interval formatter.
* @internal ICU 4.0
* @deprecated This API is ICU internal only.
*/
public DateIntervalInfo()
{
@ -279,10 +302,9 @@ public class DateIntervalInfo implements Cloneable, Freezable, Serializable {
}
/**
/*
* Initialize the DateIntervalInfo from locale
* @param locale the given locale.
* @draft ICU 4.0
*/
private void initializeData(ULocale locale)
{
@ -304,10 +326,9 @@ public class DateIntervalInfo implements Cloneable, Freezable, Serializable {
/**
/*
* Initialize DateIntervalInfo from another instance
* @param dii an DateIntervalInfo instance
* @draft ICU 4.0
*/
private void initializeData(DateIntervalInfo dii) {
fFallbackIntervalPattern = dii.fFallbackIntervalPattern;
@ -316,15 +337,14 @@ public class DateIntervalInfo implements Cloneable, Freezable, Serializable {
}
/**
/*
* Initialize DateIntervalInfo from calendar data
* @param calData calendar data
* @draft ICU 4.0
*/
private void initializeData(CalendarData calData) {
int DEFAULT_HASH_SIZE = 19;
fIntervalPatterns = new HashMap(DEFAULT_HASH_SIZE);
// initilize to guard if there is no interval date format defined in
// initialize to guard if there is no interval date format defined in
// resource files
fFallbackIntervalPattern = "{0} \u2013 {1}";
try {
@ -372,11 +392,10 @@ public class DateIntervalInfo implements Cloneable, Freezable, Serializable {
}
/**
/*
* Split interval patterns into 2 part.
* @param intervalPattern interval pattern
* @return the index in interval pattern which split the pattern into 2 part
* @draft ICU 4.0
*/
private static int splitPatternInto2Part(String intervalPattern) {
boolean inQuote = false;
@ -520,7 +539,6 @@ public class DateIntervalInfo implements Cloneable, Freezable, Serializable {
* @param intervalPattern the interval pattern on the largest different
* calendar unit.
* @return the interval pattern pattern information
* @draft ICU 4.0
*/
private PatternInfo setIntervalPatternInternally(String skeleton,
String lrgDiffCalUnit,
@ -558,7 +576,6 @@ public class DateIntervalInfo implements Cloneable, Freezable, Serializable {
* @param skeleton skeleton on which the interval pattern based
* @param lrgDiffCalUnit the largest different calendar unit.
* @param ptnInfo interval pattern infomration
* @draft ICU 4.0
*/
private void setIntervalPattern(String skeleton,
String lrgDiffCalUnit,
@ -575,6 +592,7 @@ public class DateIntervalInfo implements Cloneable, Freezable, Serializable {
* is earlier date or later date
* @return pattern info object
* @internal ICU 4.0
* @deprecated This API is ICU internal only.
*/
static PatternInfo genPatternInfo(String intervalPattern,
boolean laterDateFirst) {
@ -670,7 +688,8 @@ public class DateIntervalInfo implements Cloneable, Freezable, Serializable {
}
/* Get default order
/**
* Get default order
* return default date ordering in interval pattern
* @draft ICU 4.0
* @provisional This API might change or be removed in a future release.
@ -684,7 +703,7 @@ public class DateIntervalInfo implements Cloneable, Freezable, Serializable {
/**
* Boilerplate. Clone this object.
* @return a copy of the object
* @draft ICU4.0
* @draft ICU4.0
* @provisional This API might change or be removed in a future release.
*/
public Object clone()
@ -696,11 +715,10 @@ public class DateIntervalInfo implements Cloneable, Freezable, Serializable {
}
/**
/*
* Clone an unfrozen DateIntervalInfo object.
* @return a copy of the object
* @throws IllegalStateException If clone is not supported
* @draft ICU4.0
*/
private Object cloneUnfrozenDII() throws IllegalStateException
{
@ -768,6 +786,7 @@ public class DateIntervalInfo implements Cloneable, Freezable, Serializable {
* @param skeleton skeleton to be parsed
* @param skeletonFieldWidth parsed skeleton field width
* @internal ICU 4.0
* @deprecated This API is ICU internal only.
*/
static void parseSkeleton(String skeleton, int[] skeletonFieldWidth) {
int PATTERN_CHAR_BASE = 0x41;
@ -778,7 +797,7 @@ public class DateIntervalInfo implements Cloneable, Freezable, Serializable {
/**
/*
* Check whether one field width is numeric while the other is string.
*
* TODO (xji): make it general
@ -788,7 +807,6 @@ public class DateIntervalInfo implements Cloneable, Freezable, Serializable {
* @param patternLetter pattern letter char
* @return true if one field width is numeric and the other is string,
* false otherwise.
* @draft ICU 4.0
*/
private static boolean stringNumeric(int fieldWidth,
int anotherFieldWidth,
@ -803,7 +821,8 @@ public class DateIntervalInfo implements Cloneable, Freezable, Serializable {
}
/**given an input skeleton, get the best match skeleton
/*
* given an input skeleton, get the best match skeleton
* which has pre-defined interval pattern in resource file.
*
* TODO (xji): set field weight or
@ -815,7 +834,6 @@ public class DateIntervalInfo implements Cloneable, Freezable, Serializable {
* 2, the only field difference is 'v' and 'z'
* -1, if there is calendar field difference between
* the best match and the input skeleton
* @internal ICU 4.0
*/
DateIntervalFormat.BestMatchInfo getBestSkeleton(String inputSkeleton) {
String bestSkeleton = inputSkeleton;
@ -888,6 +906,11 @@ public class DateIntervalInfo implements Cloneable, Freezable, Serializable {
return new DateIntervalFormat.BestMatchInfo(bestSkeleton, bestFieldDifference);
}
/**
* Override equals
* @draft ICU 4.0
* @provisional This API might change or be removed in a future release.
*/
public boolean equals(Object a) {
if ( a instanceof DateIntervalInfo ) {
DateIntervalInfo dtInfo = (DateIntervalInfo)a;
@ -896,18 +919,23 @@ public class DateIntervalInfo implements Cloneable, Freezable, Serializable {
return false;
}
/**
* Override hashcode
* @draft ICU 4.0
* @provisional This API might change or be removed in a future release.
*/
public int hashCode() {
return fIntervalPatterns.hashCode();
}
/**
/*
* WriteObject.
*/
//private void writeObject(ObjectOutputStream stream) throws IOException{
// stream.defaultWriteObject();
//}
/**
/*
* readObject.
*/
//private void readObject(ObjectInputStream stream)

View file

@ -14,7 +14,8 @@ import java.io.Serializable;
* This class represents date interval.
* It is a pair of long representing from long 1 to long 2.
* @draft ICU 4.0
**/
* @provisional This API might change or be removed in a future release.
*/
public final class DateInterval implements Serializable {
private static final long serialVersionUID = 1;
@ -27,6 +28,7 @@ public final class DateInterval implements Serializable {
* @param from The from date in date interval.
* @param to The to date in date interval.
* @draft ICU 4.0
* @provisional This API might change or be removed in a future release.
*/
public DateInterval(long from, long to)
{
@ -38,6 +40,7 @@ public final class DateInterval implements Serializable {
* Get the from date.
* @return the from date in dateInterval.
* @draft ICU 4.0
* @provisional This API might change or be removed in a future release.
*/
public long getFromDate()
{
@ -48,12 +51,18 @@ public final class DateInterval implements Serializable {
* Get the to date.
* @return the to date in dateInterval.
* @draft ICU 4.0
* @provisional This API might change or be removed in a future release.
*/
public long getToDate()
{
return toDate;
}
/**
* Override equals
* @draft ICU 4.0
* @provisional This API might change or be removed in a future release.
*/
public boolean equals(Object a) {
if ( a instanceof DateInterval ) {
DateInterval di = (DateInterval)a;
@ -62,12 +71,22 @@ public final class DateInterval implements Serializable {
return false;
}
/**
* Override hashcode
* @draft ICU 4.0
* @provisional This API might change or be removed in a future release.
*/
public int hashCode() {
return (int)(fromDate + toDate);
}
public String toString() {
return String.valueOf(fromDate) + " " + String.valueOf(toDate);
}
/**
* Override toString
* @draft ICU 4.0
* @provisional This API might change or be removed in a future release.
*/
public String toString() {
return String.valueOf(fromDate) + " " + String.valueOf(toDate);
}
} // end class DateInterval