{
PeriodFormatterService pfs = BasicPeriodFormatterService.getInstance();
PeriodBuilder pb = pfs.newPeriodBuilderFactory()
.setAllowMilliseconds(false)
.getSingleUnitBuilder();
DurationFormatter df = pfs.newDurationFormatterFactory()
.setPeriodBuilder(pb)
.getFormatter();
String result = df.formatDurationFromNow(500);
assertEquals(
"english test case",
"less than 1 second from now",
result);
}
// if the limit is set on milliseconds, and they are not supported,
// use an effective limit based on seconds
{
PeriodFormatterService pfs = BasicPeriodFormatterService.getInstance();
PeriodBuilder pb = pfs.newPeriodBuilderFactory()
.setMinLimit(2500)
.setAllowMilliseconds(false)
.getSingleUnitBuilder();
DurationFormatter df = pfs.newDurationFormatterFactory()
.setPeriodBuilder(pb)
.getFormatter();
String result = df.formatDurationFromNow(500);
assertEquals(
"limit test case",
"less than 2 seconds from now",
result);
}