thomasmueller commented on code in PR #1203:
URL: https://github.com/apache/jackrabbit-oak/pull/1203#discussion_r1390691682


##########
oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/FormattingUtils.java:
##########
@@ -18,18 +18,28 @@
 
 import org.apache.jackrabbit.guava.common.base.Stopwatch;
 
-import java.time.LocalTime;
-import java.time.format.DateTimeFormatter;
 import java.util.concurrent.TimeUnit;
 
 public class FormattingUtils {
     public static String formatToSeconds(Stopwatch stopwatch) {
-        LocalTime seconds = 
LocalTime.ofSecondOfDay(stopwatch.elapsed(TimeUnit.SECONDS));
-        return DateTimeFormatter.ISO_TIME.format(seconds);
+        long seconds = stopwatch.elapsed(TimeUnit.SECONDS);
+        long absSeconds = Math.abs(seconds);

Review Comment:
   That way we don't detect if the time went backwards, which may be the case 
in some edge case.



##########
oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/FormattingUtils.java:
##########
@@ -18,18 +18,28 @@
 
 import org.apache.jackrabbit.guava.common.base.Stopwatch;
 
-import java.time.LocalTime;
-import java.time.format.DateTimeFormatter;
 import java.util.concurrent.TimeUnit;
 
 public class FormattingUtils {
     public static String formatToSeconds(Stopwatch stopwatch) {
-        LocalTime seconds = 
LocalTime.ofSecondOfDay(stopwatch.elapsed(TimeUnit.SECONDS));
-        return DateTimeFormatter.ISO_TIME.format(seconds);
+        long seconds = stopwatch.elapsed(TimeUnit.SECONDS);
+        long absSeconds = Math.abs(seconds);
+        return String.format(
+                "%02d:%02d:%02d",
+                absSeconds / 3600,

Review Comment:
   The formulas look correct, but it should be possible to use Java utilities...
   
   ```
   long millis = -123456789;
   long hours = Math.abs(TimeUnit.MILLISECONDS.toHours(millis));
   long minutes = Math.abs(TimeUnit.MILLISECONDS.toMinutes(millis)) % 60;
   long seconds = Math.abs(TimeUnit.MILLISECONDS.toSeconds(millis)) % 60;
   long milliseconds = Math.abs(millis) % 1000;
   
   String formattedTime = String.format("%s%02d:%02d:%02d.%03d", millis < 0 ? 
"-" : "", hours, minutes, seconds, milliseconds);
   System.out.println(formattedTime);
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to