Class Time4jDurationFormatter
- All Implemented Interfaces:
DurationFormatter
DurationFormatter
implementation that uses the Time4J library's PrettyTime
to render Duration
values as human-readable, localized strings.
This formatter decomposes the Duration
into calendar and clock units and uses Time4J’s
formatting capabilities to generate grammatically correct, locale-aware strings with wide text style.
For example, a duration of 2 days, 3 hours, and 4 minutes might be rendered as:
"2 days, 3 hours, and 4 minutes"
in English, or a culturally appropriate equivalent in other locales.
If the provided Duration
or ChronoUnit
is null
, this class falls back
to a default duration of 0 and a default lower bound of ChronoUnit.MINUTES
, respectively,
with warnings logged through the configured logging strategy.
The lowerBound
determines the level of truncation applied before formatting. For example,
a lower bound of ChronoUnit.MINUTES
would discard all precision below minutes.
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionTime4jDurationFormatter
(LocaleProvider localeProvider) Constructs aTime4jDurationFormatter
with the providedLocaleProvider
. -
Method Summary
Modifier and TypeMethodDescriptionformat
(Duration duration, ChronoUnit lowerBound) Formats aDuration
using Time4J'sPrettyTime
engine.
-
Constructor Details
-
Time4jDurationFormatter
Constructs aTime4jDurationFormatter
with the providedLocaleProvider
.- Parameters:
localeProvider
- supplies theLocale
to use for formatting
-
-
Method Details
-
format
Formats aDuration
using Time4J'sPrettyTime
engine. The duration is truncated to the givenlowerBound
, and formatted into a locale-sensitive string usingTextWidth.WIDE
.The method maps Java
Duration
to Time4J'sDuration
classes by separating calendar and clock units before composing them for formatting.- Specified by:
format
in interfaceDurationFormatter
- Parameters:
duration
- the duration to format;null
defaults toDuration.ZERO
lowerBound
- the lowest time unit to preserve;null
defaults toChronoUnit.MINUTES
- Returns:
- a localized, human-friendly string representation of the duration
-