Class KiwiDurationFormatters

java.lang.Object
org.kiwiproject.time.KiwiDurationFormatters

public final class KiwiDurationFormatters extends Object
Utilities for formatting durations of various types.

See Apache Commons DurationFormatUtils for even more formatter methods.

Implementation Note:
dropwizard-util must be a dependency or code using this class won't compile; this requirement will be necessary until the deprecated methods are removed.
  • Method Details

    • formatDurationWords

      @Deprecated(since="4.6.0", forRemoval=true) @KiwiDeprecated(replacedBy="formatJavaDurationWords(java.time.Duration duration)", usageSeverity=SEVERE, removeAt="5.0.0") public static String formatDurationWords(Duration duration)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Formats a Java Duration using English words. Converts the duration to millis and then calls formatDurationWords(long).
      Parameters:
      duration - the Java duration to format
      Returns:
      the duration in words (e.g., 2 hours 5 minutes)
    • formatJavaDurationWords

      public static String formatJavaDurationWords(Duration duration)
      Formats a Java Duration using English words. Converts the duration to millis and then calls formatMillisecondDurationWords(long).
      Parameters:
      duration - the Java duration to format
      Returns:
      the duration in words (e.g., 2 hours 5 minutes)
    • formatDurationWords

      @Deprecated(since="4.6.0", forRemoval=true) @KiwiDeprecated(replacedBy="formatDropwizardDurationWords(io.dropwizard.util.Duration duration)", usageSeverity=SEVERE, removeAt="5.0.0") public static String formatDurationWords(io.dropwizard.util.Duration duration)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Formats a Dropwizard io.dropwizard.util.Duration using English words. Converts the duration to millis and then calls formatDurationWords(long).
      Parameters:
      duration - the Dropwizard duration to format
      Returns:
      the duration in words (e.g., 1 minute 45 seconds)
      Implementation Note:
      You will need the Dropwizard Duration class available at runtime to call this method!
    • formatDropwizardDurationWords

      public static String formatDropwizardDurationWords(io.dropwizard.util.Duration duration)
      Formats a Dropwizard Duration using English words. Converts the duration to millis and then calls formatMillisecondDurationWords(long).
      Parameters:
      duration - the Dropwizard duration to format
      Returns:
      the duration in words (e.g., 1 minute 45 seconds)
      Implementation Note:
      You will need the Dropwizard Duration class available at runtime to call this method!
    • formatDurationWords

      @Deprecated(since="4.6.0", forRemoval=true) @KiwiDeprecated(replacedBy="formatMillisecondDurationWords(long durationMillis)", usageSeverity=SEVERE, removeAt="5.0.0") public static String formatDurationWords(long durationMillis)
      Deprecated, for removal: This API element is subject to removal in a future version.
      for removal; replaced by formatMillisecondDurationWords(long)
      A thin wrapper around DurationFormatUtils.formatDurationWords(long, boolean, boolean) that always suppresses leading and trailing "zero elements" because why would you want to see "0 days 7 hours 25 minutes 0 seconds" instead of just "7 hours 25 minutes"? (We cannot think of a good reason...)
      Parameters:
      durationMillis - the duration in milliseconds to format
      Returns:
      the duration in words (e.g., 10 minutes)
      See Also:
      • DurationFormatUtils.formatDurationWords(long, boolean, boolean)
      Implementation Note:
      The only real reason for this method to exist is, so we don't constantly have to pass the two boolean arguments. Plus, boolean arguments are evil because what exactly does "true, false" tell you without requiring you to look at the parameter documentation?
    • formatMillisecondDurationWords

      public static String formatMillisecondDurationWords(long durationMillis)
      A thin wrapper around DurationFormatUtils.formatDurationWords(long, boolean, boolean) that always suppresses leading and trailing "zero elements" because why would you want to see "0 days 7 hours 25 minutes 0 seconds" instead of just "7 hours 25 minutes"? (We cannot think of a good reason...)
      Parameters:
      durationMillis - the duration in milliseconds to format
      Returns:
      the duration in words (e.g., 10 minutes)
      See Also:
      • DurationFormatUtils.formatDurationWords(long, boolean, boolean)
      Implementation Note:
      The only real reason for this method to exist is, so we don't constantly have to pass the two boolean arguments. Plus, boolean arguments are evil because what exactly does "true, false" tell you without requiring you to look at the parameter documentation?