Skip to content

Commit 6ba31f7

Browse files
Update music system track length formatting to properly include hours
1 parent 5c926a2 commit 6ba31f7

1 file changed

Lines changed: 11 additions & 5 deletions

File tree

src/main/java/technobot/listeners/MusicListener.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
import java.net.MalformedURLException;
2727
import java.util.Objects;
28+
import java.util.concurrent.TimeUnit;
2829

2930
/**
3031
* Module for music player backend and voice channel events.
@@ -50,11 +51,16 @@ public MusicListener() {
5051
* @return string of track length (ex. 2:11)
5152
*/
5253
public static @NotNull String formatTrackLength(long trackLength) {
53-
long msPos = trackLength;
54-
long minPos = msPos / 60000;
55-
msPos = msPos % 60000;
56-
int secPos = (int) Math.floor((float) msPos / 1000f);
57-
return minPos + ":" + ((secPos < 10) ? "0" + secPos : secPos);
54+
long hours = TimeUnit.MILLISECONDS.toHours(trackLength);
55+
long minutes = TimeUnit.MILLISECONDS.toMinutes(trackLength) - TimeUnit.HOURS.toMinutes(TimeUnit.MILLISECONDS.toHours(trackLength));
56+
long seconds = TimeUnit.MILLISECONDS.toSeconds(trackLength) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(trackLength));
57+
String time = "";
58+
if (hours > 0) time += hours + ":";
59+
if (minutes < 10 && hours > 0) time += "0";
60+
time += minutes + ":";
61+
if (seconds < 10) time += "0";
62+
time += seconds;
63+
return time;
5864
}
5965

6066
/**

0 commit comments

Comments
 (0)