toMinuteString(Duration)   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 3
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
package de.pewpewproject.lasertag.common.util;
2
3
import java.time.Duration;
4
5
/**
6
 * Utils for durations
7
 *
8
 * @author Étienne Muser
9
 */
10
public class DurationUtils {
11
    /**
12
     * Converts a duration into a string of format h:mm:ss
13
     * @param d The duration to convert
14
     * @return The converted string
15
     */
16
    public static String toString(Duration d) {
17
        var s = d.getSeconds();
18
        return String.format("%d:%02d:%02d", s / 3600, (s % 3600) / 60, (s % 60));
19
    }
20
21
    /**
22
     * Converts a duration into a string of format mm:ss. If the minutes go over 60 it simply counts up. eg 61, 62,...
23
     * @param d The duration to convert
24
     * @return The converted string
25
     */
26
    public static String toMinuteString(Duration d) {
27
        var s = d.getSeconds();
28
        return String.format("%02d:%02d", s / 60, (s % 60));
29
    }
30
}
31