Skip to content

Commit

Permalink
Add formatting for "infinite" time durations
Browse files Browse the repository at this point in the history
  • Loading branch information
zxtej committed Nov 30, 2024
1 parent 7177cce commit 44875ea
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions core/src/mindustry/core/UI.java
Original file line number Diff line number Diff line change
Expand Up @@ -738,9 +738,13 @@ public static String formatAmount(long number, boolean extraDP){
}

public static String formatTime(float ticks){
int s = (int)(ticks / Time.toSeconds) % 60; // Round seconds so they don't display weird
int m = (int)(ticks / Time.toMinutes) % 60;
int s = (int)(ticks / Time.toSeconds); // Round seconds so they don't display weird
int m = (int)(ticks / Time.toMinutes);
int h = (int)(ticks / Time.toHours);
if(h == Integer.MAX_VALUE) return "∞";
// if m == int max, it will underflow to positive. Now use this mask to set m to 0
m = (m & ((-2 - m) >> 31)) % 60;
s = (s & ((-2 - s) >> 31)) % 60;
String out = (h == 0 ? "" : h + "h") + (m == 0 ? "" : m + "m") + (s == 0 ? "" : s + "s");
return out.isEmpty() ? "0s" : out;
}
Expand Down

0 comments on commit 44875ea

Please sign in to comment.