This fixes all tests except twoDaysAndAHalf
:
private static final PeriodFormatter dateFormat = new PeriodFormatterBuilder() .appendDays() .appendSuffix(" day", " days") .appendSeparator(" ") .printZeroIfSupported() .minimumPrintedDigits(2) .appendHours() .appendSeparator(":") .appendMinutes() .printZeroIfSupported() .minimumPrintedDigits(2) .appendSeparator(":") .appendSeconds() .minimumPrintedDigits(2) .toFormatter();
EDIT:
Perhaps your twoDaysAndAHalf
test should be like this?
@Test public void twoDaysAndAHalf(){ final int secondsInDay = 60 * 60 * 24; assertEquals("2 days and 12:00:00", OurDateTimeFormatter.format(1000 * secondsInDay * 5 / 2)); }
Then use this (slightly edited):
private static final PeriodFormatter dateFormat = .appendDays() .appendSuffix(" day", " days") .appendSeparator(" and ")
and he works
source share