|
16 | 16 | import vc.util.PlayerLookup; |
17 | 17 |
|
18 | 18 | import java.net.http.HttpTimeoutException; |
| 19 | +import java.util.ArrayList; |
| 20 | +import java.util.List; |
19 | 21 |
|
20 | 22 | import static discord4j.common.util.TimestampFormat.SHORT_DATE_TIME; |
21 | 23 | import static org.slf4j.LoggerFactory.getLogger; |
@@ -103,14 +105,21 @@ private String formatDuration(long durationInSeconds) { |
103 | 105 | var secondsInHour = secondsInMinute * 60L; |
104 | 106 | var secondsInDay = secondsInHour * 24L; |
105 | 107 | var secondsInMonth = secondsInDay * 30L; // assuming 30 days per month |
| 108 | + var secondsInYear = secondsInMonth * 12L; |
106 | 109 |
|
107 | | - var months = durationInSeconds / secondsInMonth; |
| 110 | + var years = durationInSeconds / secondsInYear; |
| 111 | + var months = (durationInSeconds % secondsInYear) / secondsInMonth; |
108 | 112 | var days = (durationInSeconds % secondsInMonth) / secondsInDay; |
109 | 113 | var hours = (durationInSeconds % secondsInDay) / secondsInHour; |
110 | | - final StringBuilder sb = new StringBuilder(); |
111 | | - sb.append((months > 0) ? months + " month" + (months != 1 ? "s" : "") + ", " : ""); |
112 | | - sb.append((days > 0) ? days + " day" + (days != 1 ? "s" : "") + ", " : ""); |
113 | | - sb.append(hours + " hour" + (hours != 1 ? "s" : "")); |
114 | | - return sb.toString(); |
| 114 | + List<String> entries = new ArrayList<>(4); |
| 115 | + if (years > 0) entries.add(years + " year" + (years != 1 ? "s" : "")); |
| 116 | + if (months > 0) entries.add(months + " month" + (months != 1 ? "s" : "")); |
| 117 | + if (days > 0) entries.add(days + " day" + (days != 1 ? "s" : "")); |
| 118 | + if (hours > 0) entries.add(hours + " hour" + (hours != 1 ? "s" : "")); |
| 119 | + if (entries.isEmpty()) { |
| 120 | + var minutes = (double) durationInSeconds / (double)secondsInMinute; |
| 121 | + return String.format("%.2f minutes", minutes); |
| 122 | + } |
| 123 | + return String.join(", ", entries); |
115 | 124 | } |
116 | 125 | } |
0 commit comments