Skip to content

Commit d4013e0

Browse files
Development: Improve time formatting in logs (#11161)
1 parent 2c5ba32 commit d4013e0

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

src/main/java/de/tum/cit/aet/artemis/core/util/TimeLogUtil.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,20 @@ public static String formatDurationFrom(long timeNanoStart) {
2323
if (durationInSeconds < 60) {
2424
return roundOffTo2DecPlaces(durationInSeconds) + "sec";
2525
}
26-
double durationInMinutes = durationInSeconds / 60.0;
26+
27+
/*
28+
* Minutes and hours need a special treatment to prevent formats like this:
29+
* '1.58min': Is this supposed to mean 1 min and 58 seconds or 1 min and 35 seconds?
30+
* '1.94hours': Here it would be obvious that something is off, but how long is that really?
31+
* This happens because there's not 100 seconds in a minute and also not 100 hours in a day.
32+
*/
33+
int durationInMinutes = (int) (durationInSeconds / 60.0);
2734
if (durationInMinutes < 60) {
28-
return roundOffTo2DecPlaces(durationInMinutes) + "min";
35+
return durationInMinutes + ":" + ((int) durationInSeconds % 60) + "min";
2936
}
30-
double durationInHours = durationInMinutes / 60.0;
31-
return roundOffTo2DecPlaces(durationInHours) + "hours";
37+
38+
int durationInHours = durationInMinutes / 60;
39+
return durationInHours + ":" + (durationInMinutes % 60) + "hours";
3240
}
3341

3442
public static String formatDuration(long durationInSeconds) {

0 commit comments

Comments
 (0)