André
André

Reputation: 143

jodaTime PeriodFormatter not formatting correctly

I have this PeriodFormatter:

PeriodFormatterBuilder()
            .appendDays()
            .appendSuffix(
                " day",
                " days")
            )
            .appendSeparator(", ")
            .printZeroRarelyLast()
            .appendHours()
            .appendSuffix(
                " hours",
                " hours"
            )
            .appendSeparator(" ")
            .appendMinutes()
            .appendSuffix(" minute")
            .toFormatter()
            .let {
                Period(Seconds.seconds(seconds.toInt())).toString(it)
            }

I want to give seconds as input and get x DAYS, x HOURS, x MINUTES back.... I get an empty String back when doing this. If i add "appendSeconds()" to the formatter creation I get the same amount of seconds back as a return value as I sent in..

I need the conversion, not just the amount, and I'm not interested in number of seconds, but how many minutes, hours and days it accounts to.. Anyone who can help?

Upvotes: 0

Views: 155

Answers (1)

Anonymous
Anonymous

Reputation: 86369

You need to use Period.normalizedStandard() to persuade your period to convert your seconds into minutes, hours and days.

            Period(Seconds.seconds(seconds.toInt())).normalizedStandard().toString(it)

(Not sure whether the empty round brackets () are needed in Kotlin. They are in Java, where I tested.)

Upvotes: 1

Related Questions