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.
-
Method Summary
Modifier and TypeMethodDescriptionstatic StringformatDurationWords(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"?static StringformatDurationWords(io.dropwizard.util.Duration duration) Formats a DropwizardDurationusing English words.static StringformatDurationWords(Duration duration) Formats a JavaDurationusing English words.
-
Method Details
-
formatDurationWords
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)
-
formatDurationWords
Formats a DropwizardDurationusing 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!
-
formatDurationWords
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?
-