Skip to content

Commit

Permalink
- add TimeFormatting.formatTime
Browse files Browse the repository at this point in the history
- Bump Version to 1.4.0
  • Loading branch information
rotgruengelb committed Apr 7, 2024
1 parent 23f5f6d commit 8b8e51c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version=1.3.0
version=1.4.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package net.rotgruengelb.nixienaut.format;

import java.util.Map;
import java.util.Objects;

public class TimeFormatting {

private static String formatTime(int time, String format) {
Map<String, Integer> values = Map.of("d", time / 1728000, "h", (time % 1728000) / 72000, "m", (time % 72000) / 1200, "s", (time % 1200) / 20, "tH", time / 72000, "tM", time / 1200, "tS", time / 20);

String[] formatSplit = format.split("%");
for (int i = 0; i < formatSplit.length; i++) {
if (Objects.equals(formatSplit[i], "\\")) {
formatSplit[i] = "%";
continue;
}
if (values.containsKey(formatSplit[i])) {
String string = values.get(formatSplit[i]).toString();
formatSplit[i] = "0".repeat(Math.max(0, 2 - string.length())) + string;
}
}
return String.join("", formatSplit);
}
}

0 comments on commit 8b8e51c

Please sign in to comment.