Skip to content

Commit

Permalink
msToTime use StringBuilder
Browse files Browse the repository at this point in the history
  • Loading branch information
HydrolienF committed Aug 21, 2024
1 parent bb856df commit 4ff68a9
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions src/main/java/fr/formiko/utils/FLUTime.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,14 @@ public static String msToTime(long ms, int nbrOfUnit, boolean dayOn) {
long[] tl = msToTimeLongArray(ms, dayOn);
int k = 0;
int i = 0;
String r = "";
StringBuilder r = new StringBuilder();
boolean first = true;
while (k < nbrOfUnit && i < 5) {
if (tl[i] > 0) {
if (!r.equals("")) {
r += " ";
if (first) {
first = false;
} else {
r.append(" ");
}
if (i == 3 && k + 1 < nbrOfUnit && tl[i + 1] > 0) { // si on doit traiter les s et les ms ensembles.
String s = "" + tl[i + 1];
Expand All @@ -40,20 +43,20 @@ public static String msToTime(long ms, int nbrOfUnit, boolean dayOn) {
while (s.length() > 1 && s.charAt(s.length() - 1) == '0') {
s = s.substring(0, s.length() - 1);
}
r += tl[i] + "," + s + ts[i].substring(2);
r.append(i).append(",").append(s).append(ts[i].substring(2));
k++;
i++;
} else {
r += tl[i] + ts[i].substring(2);
r.append(tl[i]).append(ts[i].substring(2));
}
k++;
}
i++;// pour ne pas sortir du tableau.
}
if (r.equals("")) {
r = tl[4] + ts[4].substring(2);
if (first) {
r.append(tl[4]).append(ts[4].substring(2));
}
return r;
return r.toString();
}
public static String msToTime(long ms) { return msToTime(ms, 2, true); }

Expand Down

0 comments on commit 4ff68a9

Please sign in to comment.