Package com.winterhavenmc.library.messagebuilder.pipeline.formatters.duration
package com.winterhavenmc.library.messagebuilder.pipeline.formatters.duration
Provides formatting for
Duration
values into localized, human-readable strings.
This package defines the DurationFormatter
interface and multiple implementations that support natural-language duration formatting.
The formatters are capable of truncating durations to a desired level of precision (e.g., minutes, hours),
classifying durations into semantic categories such as normal, unlimited, or less-than-threshold,
and formatting them accordingly.
Implementations
Time4jDurationFormatter
: Uses the Time4JPrettyTime
engine to generate fluent, grammatically correct and locale-aware representations of durations, such as "2 days, 3 hours, 4 minutes".LocalizedDurationFormatter
: Wraps anotherDurationFormatter
and handles special classifications like unlimited or sub-threshold ("less than") durations, using constant strings from the language file if present.
Classification
Durations are classified using DurationType
:
NORMAL
– a standard duration is formatted directly by the delegate formatter.UNLIMITED
– a negative duration represents "unlimited" and is rendered with a symbol or constant string.LESS_THAN
– durations smaller than the configuredChronoUnit
precision are considered less than a measurable threshold and rendered with a prefix "<" if a constant string is not found. The constant string has a placeholder for{DURATION}
, to accommodate languages that may have a different word order.
Fallback Behavior
If no matching constant is found in the language file for TIME.UNLIMITED
or TIME.LESS_THAN
,
the formatter uses language-agnostic fallback symbols:
"∞"
– for unlimited durations"< {DURATION}"
– for less-than durations, where{DURATION}
is replaced with the formatted unit
- See Also:
-
ClassDescriptionA simple data container that encapsulates a
Duration
and its corresponding lower bound of precision, represented by aChronoUnit
.FormatsDuration
values into localized human-readable strings.Enumeration representing the classification of aDuration
for use in formatting logic and conditional display of duration-related values.ADurationFormatter
implementation that localizes duration strings using configurable constants from the language file, while delegating formatting of standard durations to another formatter.ADurationFormatter
implementation that uses the Time4J library'sPrettyTime
to renderDuration
values as human-readable, localized strings.