mirror of
https://github.com/unicode-org/icu.git
synced 2025-04-08 06:53:45 +00:00
ICU-6157 merge from branch
X-SVN-Rev: 24059
This commit is contained in:
parent
779c4bfa7c
commit
3f4701f0c8
2 changed files with 309 additions and 0 deletions
1
.gitattributes
vendored
1
.gitattributes
vendored
|
@ -216,6 +216,7 @@ 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
|
||||
|
|
|
@ -0,0 +1,308 @@
|
|||
//##header J2SE15
|
||||
/*
|
||||
*******************************************************************************
|
||||
* Copyright (C) 2001-2008, International Business Machines Corporation and *
|
||||
* others. All Rights Reserved. *
|
||||
*******************************************************************************
|
||||
*/
|
||||
|
||||
/**
|
||||
* Port From: ICU4C v1.8.1 : format : DateIntervalFormatTest
|
||||
* Source File: $ICU4CRoot/source/test/intltest/dtifmtts.cpp
|
||||
**/
|
||||
|
||||
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 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 void main(String[] args) throws Exception {
|
||||
new DateIntervalFormatTest().run(args);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* General parse/format tests. Add test cases as needed.
|
||||
*/
|
||||
public void TestFormat() {
|
||||
// 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",
|
||||
"2007 10 10 10:10:10", "2007 11 10 10:10:10",
|
||||
"2007 11 10 10:10:10", "2007 11 20 10:10:10",
|
||||
"2007 01 10 10:00:10", "2007 01 10 14:10:10",
|
||||
"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", "", ""},
|
||||
{"de", "", ""},
|
||||
{"ar", "", ""},
|
||||
{"en", "GB", ""},
|
||||
{"fr", "", ""},
|
||||
{"it", "", ""},
|
||||
{"nl", "", ""},
|
||||
{"zh", "TW", ""},
|
||||
{"ja", "", ""},
|
||||
{"pt", "BR", ""},
|
||||
{"ru", "", ""},
|
||||
{"pl", "", ""},
|
||||
{"tr", "", ""},
|
||||
{"es", "", ""},
|
||||
{"ko", "", ""},
|
||||
{"th", "", ""},
|
||||
{"sv", "", ""},
|
||||
{"fi", "", ""},
|
||||
{"da", "", ""},
|
||||
{"pt", "PT", ""},
|
||||
{"ro", "", ""},
|
||||
{"hu", "", ""},
|
||||
{"he", "", ""},
|
||||
{"in", "", ""},
|
||||
{"cs", "", ""},
|
||||
{"el", "", ""},
|
||||
{"no", "", ""},
|
||||
{"vi", "", ""},
|
||||
{"bg", "", ""},
|
||||
{"hr", "", ""},
|
||||
{"lt", "", ""},
|
||||
{"sk", "", ""},
|
||||
{"sl", "", ""},
|
||||
{"sr", "", ""},
|
||||
{"ca", "", ""},
|
||||
{"lv", "", ""},
|
||||
{"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) {
|
||||
expect(DATA, DATA.length, new Locale(testLocale[localeIndex][0],
|
||||
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[] skeleton = {
|
||||
"EEEEdMMMMy",
|
||||
"dMMMMy",
|
||||
"dMMMM",
|
||||
"MMMMy",
|
||||
"EEEEdMMMM",
|
||||
"EEEdMMMy",
|
||||
"dMMMy",
|
||||
"dMMM",
|
||||
"MMMy",
|
||||
"EEEdMMM",
|
||||
"EEEdMy",
|
||||
"dMy",
|
||||
"dM",
|
||||
"My",
|
||||
"EEEdM",
|
||||
"d",
|
||||
"EEEd",
|
||||
"y",
|
||||
"M",
|
||||
"MMM",
|
||||
"MMMM",
|
||||
"hm",
|
||||
"hmv",
|
||||
"hmz",
|
||||
"h",
|
||||
"hv",
|
||||
"hz",
|
||||
"EEddMMyyyy", // following could be normalized
|
||||
"EddMMy",
|
||||
"hhmm",
|
||||
"hhmmzz",
|
||||
"hms", // following could not be normalized
|
||||
"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");
|
||||
|
||||
if ( DEBUG ) {
|
||||
osw.write("locale: " + locName + "\n");
|
||||
}
|
||||
|
||||
while (i<data_length) {
|
||||
// 'f'
|
||||
String datestr = data[i++];
|
||||
String datestr_2 = data[i++];
|
||||
if ( DEBUG ) {
|
||||
osw.write("original date: " + datestr + " - " + datestr_2 + "\n");
|
||||
}
|
||||
Date date;
|
||||
Date date_2;
|
||||
try {
|
||||
date = ref.parse(datestr);
|
||||
date_2 = ref.parse(datestr_2);
|
||||
} catch ( ParseException e ) {
|
||||
errln("parse exception" + e);
|
||||
continue;
|
||||
}
|
||||
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);
|
||||
FieldPosition pos = new FieldPosition(0);
|
||||
StringBuffer str = new StringBuffer("");
|
||||
dtitvfmt.format(dtitv, str, pos);
|
||||
if ( DEBUG ) {
|
||||
osw.write("interval by skeleton: " + oneSkeleton + "\n");
|
||||
osw.write("interval date: " + str + "\n");
|
||||
}
|
||||
}
|
||||
|
||||
// test user created DateIntervalInfo
|
||||
DateIntervalInfo dtitvinf = new DateIntervalInfo();
|
||||
dtitvinf.setFallbackIntervalPattern("{0} --- {1}");
|
||||
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);
|
||||
FieldPosition pos = new FieldPosition(0);
|
||||
StringBuffer str = new StringBuffer("");
|
||||
dtitvfmt.format(dtitv, str, pos);
|
||||
if ( DEBUG ) {
|
||||
osw.write("interval format using user defined DateIntervalInfo\n");
|
||||
osw.write("interval date: " + str + "\n");
|
||||
}
|
||||
|
||||
// test interval format used by CLDR survey tool
|
||||
//dtitvfmt = DateIntervalFormat.getEmptyInstance();
|
||||
dtitvfmt = DateIntervalFormat.getInstance();
|
||||
SimpleDateFormat dtfmt = new SimpleDateFormat("yyyy 'year' MMM 'month' dd 'day'", loc);
|
||||
dtitvfmt.setDateFormat(dtfmt);
|
||||
dtitvinf = new DateIntervalInfo();
|
||||
dtitvinf.setFallbackIntervalPattern("{0} --- {1}");
|
||||
dtitvinf.setIntervalPattern("yMMMd", Calendar.YEAR, "'all diff'");
|
||||
dtitvinf.setIntervalPattern("yMMMd", Calendar.MONTH, "yyyy 'diff' MMM d - MMM y");
|
||||
dtitvinf.setIntervalPattern("yMMMd", Calendar.DATE, "yyyy MMM d ~ d");
|
||||
dtitvinf.setIntervalPattern("yMMMd", Calendar.HOUR_OF_DAY, "yyyy MMM d HH:mm ~ HH:mm");
|
||||
dtitvfmt.setDateIntervalInfo(dtitvinf);
|
||||
pos = new FieldPosition(0);
|
||||
str = new StringBuffer("");
|
||||
//dtitvfmt.format(dtitv, str, pos);
|
||||
Calendar fromCalendar = (Calendar) dtfmt.getCalendar().clone();
|
||||
Calendar toCalendar = (Calendar) dtfmt.getCalendar().clone();
|
||||
fromCalendar.setTimeInMillis(dtitv.getFromDate());
|
||||
toCalendar.setTimeInMillis(dtitv.getToDate());
|
||||
dtitvfmt.format(fromCalendar, toCalendar, str, pos);
|
||||
if ( DEBUG ) {
|
||||
osw.write("interval format for CLDR\n");
|
||||
osw.write("interval date: " + str + "\n");
|
||||
}
|
||||
|
||||
// test interval format by algorithm
|
||||
for ( int style = DateFormat.FULL; style < 4; ++style ) {
|
||||
dtfmt = (SimpleDateFormat) DateFormat.getDateInstance(style, loc);
|
||||
pos = new FieldPosition(0);
|
||||
str = new StringBuffer("");
|
||||
fromCalendar = (Calendar) dtfmt.getCalendar().clone();
|
||||
toCalendar = (Calendar) dtfmt.getCalendar().clone();
|
||||
fromCalendar.setTimeInMillis(dtitv.getFromDate());
|
||||
toCalendar.setTimeInMillis(dtitv.getToDate());
|
||||
dtfmt.intervalFormatByAlgorithm(fromCalendar, toCalendar, str, pos);
|
||||
if ( DEBUG ) {
|
||||
osw.write("interval format by algorithm, style = " + style + "\n");
|
||||
osw.write("interval date: " + str + "\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
osw.close();
|
||||
} catch ( FileNotFoundException e) {
|
||||
errln("file not found\n");
|
||||
return;
|
||||
} catch ( UnsupportedEncodingException e) {
|
||||
errln("UTF-8 is not supported\n");
|
||||
return;
|
||||
} catch ( IOException e ) {
|
||||
errln("IOException: " + e);
|
||||
return;
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
Loading…
Add table
Reference in a new issue