Skip to content

Commit

Permalink
Don't waste time on formatting the string twice
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexProgrammerDE committed Nov 1, 2022
1 parent 9e94ffb commit 6c74d97
Showing 1 changed file with 3 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,9 @@ private SharedChatUtils() {
}

public static String formatDuration(String str, Duration duration, int position) {
String format = String.format("%dh %dm", duration.toHours(), duration.toMinutes() % 60);

if (duration.toHours() == 0)
format = String.format("%dm", duration.toMinutes() == 0 ? 1 : duration.toMinutes());
String format = duration.toHours() == 0 ?
String.format("%dm", duration.toMinutes() == 0 ? 1 : duration.toMinutes()) :
String.format("%dh %dm", duration.toHours(), duration.toMinutes() % 60);

return str.replace("%position%", String.valueOf(position)).replace("%wait%", format);
}
Expand Down

0 comments on commit 6c74d97

Please sign in to comment.