Class TimeDurationFormatter

java.lang.Object
org.apache.jackrabbit.oak.commons.TimeDurationFormatter

public class TimeDurationFormatter extends Object
Format a time duration as human-readable string, inspired by Stopwatch#toString().
  • Constructor Details

    • TimeDurationFormatter

      public TimeDurationFormatter(Locale locale, int threshold, boolean allowNonAscii)
      Parameters:
      locale - locale for formatting (affects the decimal point)
      threshold - integral value that needs to be exceeded to switch to a certain time unit for display (e.g., specify 2 to switch to 'days' when the elapsed time is two or more days.
      allowNonAscii - set to true if the display unit can use the non-ASCII "micro" Unicode character
  • Method Details

    • forLogging

      public static TimeDurationFormatter forLogging()
      Default formatter suitable for logging (ASCII-only)
    • format

      public String format(long amount, TimeUnit unit)
      Format the specified duration
      Parameters:
      amount - number of time units
      unit - time unit