Package org.kiwiproject.time
Class KiwiDurationFormatters
java.lang.Object
org.kiwiproject.time.KiwiDurationFormatters
Utilities for formatting durations of various types.
See Apache Commons DurationFormatUtils for even more formatter methods.
- Implementation Note:
dropwizard-utilmust be a dependency or code using this class won't compile; this requirement will be necessary until the deprecated methods are removed.
-
Method Summary
Modifier and TypeMethodDescriptionstatic StringformatDropwizardDurationWords(io.dropwizard.util.Duration duration) Formats a DropwizardDurationusing English words.static StringformatDurationWords(long durationMillis) Deprecated, for removal: This API element is subject to removal in a future version.static StringformatDurationWords(io.dropwizard.util.Duration duration) Deprecated, for removal: This API element is subject to removal in a future version.for removal; replaced byformatDropwizardDurationWords(Duration)static StringformatDurationWords(Duration duration) Deprecated, for removal: This API element is subject to removal in a future version.for removal; replaced byformatJavaDurationWords(java.time.Duration)static StringformatJavaDurationWords(Duration duration) Formats a JavaDurationusing English words.static StringformatMillisecondDurationWords(long durationMillis) A thin wrapper aroundDurationFormatUtils.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"?
-
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.for removal; replaced byformatJavaDurationWords(java.time.Duration)Formats a JavaDurationusing English words. Converts the duration to millis and then callsformatDurationWords(long).- Parameters:
duration- the Java duration to format- Returns:
- the duration in words (e.g., 2 hours 5 minutes)
-
formatJavaDurationWords
Formats a JavaDurationusing English words. Converts the duration to millis and then callsformatMillisecondDurationWords(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.for removal; replaced byformatDropwizardDurationWords(Duration)Formats a Dropwizardio.dropwizard.util.Durationusing English words. Converts the duration to millis and then callsformatDurationWords(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
Formats a DropwizardDurationusing English words. Converts the duration to millis and then callsformatMillisecondDurationWords(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 byformatMillisecondDurationWords(long)A thin wrapper aroundDurationFormatUtils.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
A thin wrapper aroundDurationFormatUtils.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(long)