ICU-3487 duration (handle milliseconds)
X-SVN-Rev: 22512
This commit is contained in:
parent
0edc6125a1
commit
ccceb4f4a8
@ -140,7 +140,6 @@ public class ICUDurationTest extends TestFmwk {
|
||||
} else {
|
||||
errln("FAIL: got " + out + " wanted " + expected + " from " + d);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -162,6 +161,13 @@ public class ICUDurationTest extends TestFmwk {
|
||||
// from BD req's
|
||||
"en", "PT2H46M40S", "2 hours, 46 minutes, and 40 seconds",
|
||||
"it", "PT2H46M40S", "due ore, 46 minuti e 40 secondi",
|
||||
|
||||
// more cases
|
||||
"en", "PT10S", "10 seconds",
|
||||
"en", "PT88M70S", "88 minutes and 70 seconds",
|
||||
"en", "PT10.100S", "10 seconds and 100 milliseconds",
|
||||
"en", "-PT10S", "10 seconds",
|
||||
"en", "PT0H5M0S", "5 minutes and 0 seconds"
|
||||
};
|
||||
|
||||
for(int n=0;n<cases.length;n+=3) {
|
||||
|
@ -142,10 +142,31 @@ public class BasicDurationFormat extends DurationFormat {
|
||||
} else {
|
||||
sawNonZero = true;
|
||||
}
|
||||
float floatVal = n.floatValue();
|
||||
// is there a 'secondary' unit to set?
|
||||
TimeUnit alternateUnit = null;
|
||||
float alternateVal = 0;
|
||||
|
||||
// see if there is a fractional part
|
||||
if(outFields[i]==TimeUnit.SECOND) {
|
||||
double fullSeconds = floatVal;
|
||||
double intSeconds = Math.floor(floatVal);
|
||||
double millis = (fullSeconds-intSeconds)*1000.0;
|
||||
if(millis > 0.0) {
|
||||
alternateUnit = TimeUnit.MILLISECOND;
|
||||
alternateVal=(float)millis;
|
||||
floatVal=(float)intSeconds;
|
||||
}
|
||||
}
|
||||
|
||||
if(p == null) {
|
||||
p = Period.at(n.floatValue(), outFields[i]);
|
||||
p = Period.at(floatVal, outFields[i]);
|
||||
} else {
|
||||
p = p.and(n.floatValue(), outFields[i]);
|
||||
p = p.and(floatVal, outFields[i]);
|
||||
}
|
||||
|
||||
if(alternateUnit != null) {
|
||||
p = p.and(alternateVal, alternateUnit); // add in MILLISECONDs
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user