I’m trying to have Joda print “0 seconds” if the input time is zero, but instead its just printing nothing at all.
The below example just outputs an empty string. Whats going on here?
PeriodFormatter hoursMinutesSeconds = new PeriodFormatterBuilder()
.appendHours().appendSuffix(" hour", " hours")
.appendSeparator(", ", " and ")
.appendMinutes()
.appendSuffix(" minute", " minutes")
.appendSeparator(" and ")
.printZeroRarelyFirst()
.appendSeconds()
.appendSuffix(" second", " seconds")
.toFormatter();
System.out.println(hoursMinutesSeconds.print(new Period(0, 0, 0, 500)));
You need an early
printZeroAlwaysand move yourprintZeroRarelyFirstup a bit to make it work to say0 hours.You might prefer the
printZeroRarelyLastsolution, though, because the method above always gives you the 0 hours.I prefer