Skip to content

Commit

Permalink
Customizable time format string
Browse files Browse the repository at this point in the history
  • Loading branch information
RecursiveG committed Aug 19, 2015
1 parent f196516 commit c3aba14
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
13 changes: 7 additions & 6 deletions src/main/java/cat/nyaa/playtimetracker/Locale.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,29 @@ public static String get(String name, String... args) {
}

public static String formatTime(long ms) {
ConfigurationSection s = lang.getConfigurationSection("statistic-time-format");
String str = "";
if (ms == 0)
return "0";
return s.getString("zero");

if (ms > 0) {
str = String.format("%dms", ms % 1000) + str;
str = String.format(s.getString("ms"), ms % 1000) + str;
ms = Math.floorDiv(ms, 1000);
}
if (ms > 0) {
str = String.format("%ds ", ms % 60) + str;
str = String.format(s.getString("s"), ms % 60) + str;
ms = Math.floorDiv(ms, 60);
}
if (ms > 0) {
str = String.format("%dm ", ms % 60) + str;
str = String.format(s.getString("m"), ms % 60) + str;
ms = Math.floorDiv(ms, 60);
}
if (ms > 0) {
str = String.format("%dh ", ms % 24) + str;
str = String.format(s.getString("h"), ms % 24) + str;
ms = Math.floorDiv(ms, 24);
}
if (ms > 0) {
str = String.format("%dd ", ms) + str;
str = String.format(s.getString("d"), ms) + str;
}

return str;
Expand Down
8 changes: 7 additions & 1 deletion src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,13 @@ message:
statistic-month: "Online time this month: %s"
statistic-session: "Online time this session: %s"
statistic-total: "Online time total: %s"
#statistic-time-format: "D'd'H'h'm'm's's'S'ms'" # http://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html
statistic-time-format:
ms: "%dms"
s: "%dseconds "
m: "%dminutes "
h: "%dhours "
d: "%ddays "
zero: "No Record"
statistic-no-record: "No record for that player."

ignore-afk: true
Expand Down

0 comments on commit c3aba14

Please sign in to comment.