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 Time4J PrettyTime engine to generate fluent, grammatically correct and locale-aware representations of durations, such as "2 days, 3 hours, 4 minutes".
  • LocalizedDurationFormatter: Wraps another DurationFormatter 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 configured ChronoUnit 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
These ensure the output remains meaningful and intelligible even in the absence of localized strings.
See Also: