When using joda time with Grails you can set the default LocalDate format as they have done here. I want to do the same thing with Duration and Period so I don't have to type something like
durationFormatter.print(exampleObject.myDuration)
every time I want to display a duration or period. I want a call to the toString()
method of a Duration
/ Period
object and have it print in the desired format.
I have tried to implement PeriodFormatter in my config file much like they did here, but to no avail. Here is what I have so far in my config file:
jodatime {
format.org.joda.time.LocalDate = "yyyy-MM-dd"
format.org.joda.time.PeriodFormatter = { new format.org.joda.time.PeriodFormatterBuilder()
.appendMonths()
.appendSuffix( " month", " months" )
.appendWeeks()
.appendSuffix( " week", " weeks" )
.appendDays()
.appendSuffix( " day", " days" )
.appendHours()
.appendSuffix( " hour", " hours" )
.toFormatter();
}
}