errln("Error instantiating XML DatatypeFactory.");
e.printStackTrace();
}
Duration d;
DurationFormat df;
String out;
String expected;
String expected2;
// test 1
d = factory.newDuration("PT2H46M40S");
df = DurationFormat.getInstance(new ULocale("en"));
expected = "2 hours, 46 minutes, and 40 seconds";
out = df.format(d);
if(out.equals(expected)) {
logln("out=expected: " + expected + " from " + d);
} else {
errln("FAIL: got " + out + " wanted " + expected + " from " + d);
}
// test 2
d = factory.newDuration(10000);
df = DurationFormat.getInstance(new ULocale("en"));
expected = "10 seconds";
out = df.format(d);
if(out.equals(expected)) {
logln("out=expected: " + expected + " from " + d);
} else {
errln("FAIL: got " + out + " wanted " + expected + " from " + d);
}
// test 3
d = factory.newDuration("P0DT0H0M10.0S");
df = DurationFormat.getInstance(new ULocale("en"));
expected = "10 seconds";
out = df.format(d);
if(out.equals(expected)) {
logln("out=expected: " + expected + " from " + d);
} else {
errln("FAIL: got " + out + " wanted " + expected + " from " + d);
}
// test 4
d = factory.newDuration(86400000);
df = DurationFormat.getInstance(new ULocale("en"));
expected = "1 day, 0 hours, 0 minutes, and 0 seconds";
expected2 = "1 day and 0 seconds"; // This is the expected result for Windows with IBM JRE6
out = df.format(d);
if(out.equals(expected)) {
logln("out=expected: " + expected + " from " + d);
} else {
if(out.equals(expected2)){
logln("WARNING: got " + out + " wanted " + expected + " from " + d);