From 44875eaaffb525faf0044d0bc2d740a66c6e802d Mon Sep 17 00:00:00 2001 From: zxtej <83355748+zxtej@users.noreply.github.com> Date: Sat, 30 Nov 2024 18:46:50 +0000 Subject: [PATCH] Add formatting for "infinite" time durations --- core/src/mindustry/core/UI.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/core/src/mindustry/core/UI.java b/core/src/mindustry/core/UI.java index 256ed1bebb..ba3f8710f0 100644 --- a/core/src/mindustry/core/UI.java +++ b/core/src/mindustry/core/UI.java @@ -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; }