use of android.icu.text.DateFormat in project j2objc by google.
the class ChineseTest method TestFormat.
/**
* Test formatting.
* Q: Why is this in Calendar tests instead of Format tests?
* Note: This test assumes that Chinese calendar formatted dates can be parsed
* unambiguously to recover the original Date that was formatted. This is not
* currently true since Chinese calendar formatted dates do not include an era.
* To address this will require formatting/parsing of fields from some other
* associated calendar, as per ICU ticket #9043. This test should be timebombed
* until that ticket is addressed.
*/
@Test
public void TestFormat() {
ChineseCalendar cal = new ChineseCalendar();
DateFormat fmt = DateFormat.getDateTimeInstance(cal, DateFormat.DEFAULT, DateFormat.DEFAULT);
java.util.Calendar tempcal = java.util.Calendar.getInstance();
tempcal.clear();
Date[] DATA = new Date[2];
tempcal.set(2001, Calendar.MAY, 22);
DATA[0] = tempcal.getTime();
tempcal.set(2001, Calendar.MAY, 23);
DATA[1] = tempcal.getTime();
for (int i = 0; i < DATA.length; ++i) {
String s = fmt.format(DATA[i]);
try {
Date e = fmt.parse(s);
if (e.equals(DATA[i])) {
logln("Ok: " + DATA[i] + " -> " + s + " -> " + e);
} else {
errln("FAIL: " + DATA[i] + " -> " + s + " -> " + e);
}
} catch (java.text.ParseException e) {
errln("Fail: " + s + " -> parse failure at " + e.getErrorOffset());
errln(e.toString());
}
}
}
use of android.icu.text.DateFormat in project j2objc by google.
the class TestMessageFormat method testNumericFormatWithMap.
@Test
public void testNumericFormatWithMap() {
MessageFormat mf = new MessageFormat("X:{2} Y:{1}");
if (mf.usesNamedArguments()) {
errln("should not use named arguments");
}
Map map12 = new HashMap();
map12.put("1", "one");
map12.put("2", "two");
String target = "X:two Y:one";
String result = mf.format(map12);
if (!target.equals(result)) {
errln("expected '" + target + "' but got '" + result + "'");
}
try {
Map mapResult = mf.parseToMap(target);
if (!map12.equals(mapResult)) {
errln("expected " + map12 + " but got " + mapResult);
}
} catch (ParseException e) {
errln("unexpected exception: " + e.getMessage());
}
Map map10 = new HashMap();
map10.put("1", "one");
map10.put("0", "zero");
target = "X:{2} Y:one";
result = mf.format(map10);
if (!target.equals(result)) {
errln("expected '" + target + "' but got '" + result + "'");
}
DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.MEDIUM);
DateFormat timeFormat = DateFormat.getTimeInstance(DateFormat.MEDIUM);
Map fmtMap = new HashMap();
fmtMap.put("1", dateFormat);
fmtMap.put("2", timeFormat);
mf.setFormatsByArgumentName(fmtMap);
Date date = new Date(661439820000L);
try {
// should fail, wrong argument type
result = mf.format(map12);
fail("expected exception but got '" + result + "'");
} catch (IllegalArgumentException e) {
// expect this
}
Map argMap = new HashMap();
argMap.put("1", date);
argMap.put("2", date);
target = "X:5:17:00 AM Y:Dec 17, 1990";
result = mf.format(argMap);
if (!target.equals(result)) {
errln("expected '" + target + "' but got '" + result + "'");
}
}
Aggregations