|
@@ -24,6 +24,7 @@ package com.dmdirc.ui.messages;
|
24
|
24
|
|
25
|
25
|
import com.dmdirc.Precondition;
|
26
|
26
|
import com.dmdirc.config.ConfigManager;
|
|
27
|
+import com.dmdirc.util.DateUtils;
|
27
|
28
|
|
28
|
29
|
import java.util.HashMap;
|
29
|
30
|
import java.util.IllegalFormatConversionException;
|
|
@@ -141,7 +142,8 @@ public final class Formatter {
|
141
|
142
|
break;
|
142
|
143
|
case 'u':
|
143
|
144
|
// Duration hacks
|
144
|
|
- res[i] = formatDuration(Integer.valueOf(String.valueOf(args[i].toString())));
|
|
145
|
+ res[i] = DateUtils.formatDuration(Integer.valueOf(
|
|
146
|
+ String.valueOf(args[i].toString())));
|
145
|
147
|
break;
|
146
|
148
|
default:
|
147
|
149
|
res[i] = args[i];
|
|
@@ -153,55 +155,6 @@ public final class Formatter {
|
153
|
155
|
return res;
|
154
|
156
|
}
|
155
|
157
|
|
156
|
|
- /**
|
157
|
|
- * Tests for and adds one component of the duration format.
|
158
|
|
- *
|
159
|
|
- * @param builder The string builder to append text to
|
160
|
|
- * @param current The number of seconds in the duration
|
161
|
|
- * @param duration The number of seconds in this component
|
162
|
|
- * @param name The name of this component
|
163
|
|
- * @return The number of seconds used by this component
|
164
|
|
- */
|
165
|
|
- private static int doDuration(final StringBuilder builder, final int current,
|
166
|
|
- final int duration, final String name) {
|
167
|
|
- int res = 0;
|
168
|
|
-
|
169
|
|
- if (current >= duration) {
|
170
|
|
- final int units = current / duration;
|
171
|
|
- res = units * duration;
|
172
|
|
-
|
173
|
|
- if (builder.length() > 0) {
|
174
|
|
- builder.append(", ");
|
175
|
|
- }
|
176
|
|
-
|
177
|
|
- builder.append(units);
|
178
|
|
- builder.append(' ');
|
179
|
|
- builder.append(name + (units != 1 ? 's' : ""));
|
180
|
|
- }
|
181
|
|
-
|
182
|
|
- return res;
|
183
|
|
- }
|
184
|
|
-
|
185
|
|
- /**
|
186
|
|
- * Formats the specified number of seconds as a string containing the
|
187
|
|
- * number of days, hours, minutes and seconds.
|
188
|
|
- *
|
189
|
|
- * @param duration The duration in seconds to be formatted
|
190
|
|
- * @return A textual version of the duration
|
191
|
|
- */
|
192
|
|
- public static String formatDuration(final int duration) {
|
193
|
|
- final StringBuilder buff = new StringBuilder();
|
194
|
|
-
|
195
|
|
- int seconds = duration;
|
196
|
|
-
|
197
|
|
- seconds -= doDuration(buff, seconds, 60*60*24, "day");
|
198
|
|
- seconds -= doDuration(buff, seconds, 60*60, "hour");
|
199
|
|
- seconds -= doDuration(buff, seconds, 60, "minute");
|
200
|
|
- seconds -= doDuration(buff, seconds, 1, "second");
|
201
|
|
-
|
202
|
|
- return buff.length() == 0 ? "0 seconds" : buff.toString();
|
203
|
|
- }
|
204
|
|
-
|
205
|
158
|
/**
|
206
|
159
|
* Analyses the specified format string and fills in the format type cache.
|
207
|
160
|
*
|