Package com.winterhavenmc.library.messagebuilder.adapters.pipeline.formatters.duration
package com.winterhavenmc.library.messagebuilder.adapters.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 Time4JPrettyTimeengine to generate fluent, grammatically correct and locale-aware representations of durations, such as "2 days, 3 hours, 4 minutes".LocalizedDurationFormatter: Wraps anotherDurationFormatterand 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 configuredChronoUnitprecision 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:
-
ClassDescriptionEnumeration representing the classification of a
Durationfor use in formatting logic and conditional display of duration-related values.ADurationFormatterimplementation that localizes duration strings using configurable constants from the language file, while delegating formatting of standard durations to another formatter.ADurationFormatterimplementation that uses the Time4J library'sPrettyTimeto renderDurationvalues as human-readable, localized strings.