Package com.norconex.commons.lang.time
Class DurationFormatter
java.lang.Object
com.norconex.commons.lang.time.DurationFormatter
Formats a duration to a string.
This class is thread-safe and immutable.
- Since:
- 2.0.0
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final DurationFormatterExample: 5D18h1m23sstatic final DurationFormatterExample: 5 days 18 hours 1 minute 23 seconds -
Constructor Summary
ConstructorsConstructorDescriptionCreates a duration with the default locale and full words for duration units. -
Method Summary
Modifier and TypeMethodDescriptionbooleanformat(long duration) Formats the given duration (in milliseconds) to a string.Formats the given duration to a string.intinthashCode()toString()withHighestUnit(DurationUnit highestUnit) Creates a copy if this formatter with the given highest unit.withInnerSeparator(String innerSeparator) Creates a copy if this formatter with the specified separator text to be inserted between the numeric and textual values.withLocale(Locale locale) Creates a copy if this formatter with the given locale.withLowestUnit(DurationUnit lowestUnit) Creates a copy if this formatter with the given lowest unit.withNumberFormat(NumberFormat numberFormat) Creates a copy if this formatter with the given number format.withOuterLastSeparator(String outerLastSeparator) Creates a copy if this formatter with the specified separator text to be inserted between the second to last and last formatter units (number and text pairs).withOuterSeparator(String outerSeparator) Creates a copy if this formatter with the specified separator text to be inserted between each formatter units (number and text pairs).withUnitFormatter(DurationUnitFormatter unitFormatter) Creates a copy if this formatter with the given unit formatter.withUnitPrecision(int unitPrecision) Creates a copy if this formatter with the given unit precision.
-
Field Details
-
COMPACT
Example: 5D18h1m23s -
FULL
Example: 5 days 18 hours 1 minute 23 seconds
-
-
Constructor Details
-
DurationFormatter
public DurationFormatter()Creates a duration with the default locale and full words for duration units.
-
-
Method Details
-
withLocale
Creates a copy if this formatter with the given locale. Default locale is English.- Parameters:
locale- locale- Returns:
- duration formatter copy
-
getLocale
-
withUnitPrecision
Creates a copy if this formatter with the given unit precision.- Parameters:
unitPrecision- unit precision- Returns:
- duration formatter copy
-
getUnitPrecision
public int getUnitPrecision() -
withNumberFormat
Creates a copy if this formatter with the given number format. Default number format isRbDurationUnitFormatter.FULL.- Parameters:
numberFormat- number format- Returns:
- duration formatter copy
-
getNumberFormat
-
withHighestUnit
Creates a copy if this formatter with the given highest unit.- Parameters:
highestUnit- highest unit- Returns:
- duration formatter copy
-
getHighestUnit
-
withLowestUnit
Creates a copy if this formatter with the given lowest unit.- Parameters:
lowestUnit- lowest unit- Returns:
- duration formatter copy
-
getLowestUnit
-
withUnitFormatter
Creates a copy if this formatter with the given unit formatter.- Parameters:
unitFormatter- unit formatter- Returns:
- duration formatter copy
-
getUnitFormatter
-
withInnerSeparator
Creates a copy if this formatter with the specified separator text to be inserted between the numeric and textual values. For instance, specifying an hyphen ('-') for a ten seconds duration would result in:10-seconds. Default is a single space character.- Parameters:
innerSeparator- inner separator- Returns:
- duration formatter copy
-
getInnerSeparator
-
withOuterSeparator
Creates a copy if this formatter with the specified separator text to be inserted between each formatter units (number and text pairs). For instance, specifying ", " for two minutes and ten seconds duration would result in:2 minutes, 10 seconds. Default is a single space character.- Parameters:
outerSeparator- outer separator- Returns:
- duration formatter copy
-
getOuterSeparator
-
withOuterLastSeparator
Creates a copy if this formatter with the specified separator text to be inserted between the second to last and last formatter units (number and text pairs). For instance, specifying " and " for 1 hour, two minutes and ten seconds duration would result in:1 hour 2 minutes and 10 seconds. Default isnull(fallsback to usinggetOuterSeparator()).- Parameters:
outerLastSeparator- last outer separator- Returns:
- duration formatter copy
-
getOuterLastSeparator
-
format
Formats the given duration to a string.- Parameters:
duration- the duration to format- Returns:
- formatted duration
-
format
Formats the given duration (in milliseconds) to a string.- Parameters:
duration- the duration to format- Returns:
- formatted duration
-
toString
-
equals
-
hashCode
public int hashCode()
-