mirror of
https://github.com/unicode-org/icu.git
synced 2025-04-07 22:44:49 +00:00
ICU-3487 fix for changed newDuration behavior
X-SVN-Rev: 22431
This commit is contained in:
parent
30785c67a8
commit
eed27eff1b
2 changed files with 27 additions and 0 deletions
|
@ -120,6 +120,27 @@ public class ICUDurationTest extends TestFmwk {
|
|||
} 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";
|
||||
out = df.format(d);
|
||||
if(out.equals(expected)) {
|
||||
logln("out=expected: " + expected + " from " + d);
|
||||
} else {
|
||||
errln("FAIL: got " + out + " wanted " + expected + " from " + d);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -133,9 +133,15 @@ public class BasicDurationFormat extends DurationFormat {
|
|||
inPast = true;
|
||||
}
|
||||
// convert a Duration to a Period
|
||||
boolean sawNonZero = false; // did we have a set, non-zero field?
|
||||
for(int i=0;i<inFields.length;i++) {
|
||||
if(duration.isSet(inFields[i])) {
|
||||
Number n = duration.getField(inFields[i]);
|
||||
if(n.intValue() == 0 && !sawNonZero) {
|
||||
continue; // ignore zero fields larger than the largest nonzero field
|
||||
} else {
|
||||
sawNonZero = true;
|
||||
}
|
||||
if(p == null) {
|
||||
p = Period.at(n.floatValue(), outFields[i]);
|
||||
} else {
|
||||
|
|
Loading…
Add table
Reference in a new issue