RelativeYearMonthLocalizer

class RelativeYearMonthLocalizer(options: RelativeYearMonthOptions = RelativeYearMonthOptions(), locale: PlatformLocale = getDefaultLocale()) : PolyglotReferenceValueLocalizer<YearMonth> (source)

Localizes a YearMonth relative to a Zoned<Instant> reference point.

As this class implements PolyglotReferenceValueLocalizer, it allows to use localizeAsFlow.

Localization could, based on options, prioritize a word style localization (e.g. last month) over a numeric style (e.g. 1 month ago).

Create once and re-use for localizing multiple values with the same options. Use YearMonth.localizeRelative or YearMonth.localizeRelativeAsFlow for one-off localizations.

Examples:

  • this month

  • last mo.

  • next month

  • 4 months ago

  • in 34mo.

See also

Constructors

Link copied to clipboard
constructor(options: RelativeYearMonthOptions = RelativeYearMonthOptions(), locale: PlatformLocale = getDefaultLocale())

Functions

Link copied to clipboard
open override fun localize(value: YearMonth, reference: Zoned<Instant>): TickingValue<String>
Link copied to clipboard
fun <T> PolyglotReferenceValueLocalizer<T>.localize(value: T, clock: Clock = Clock.System): TickingValue<String>

Localizes value by using the given clock's Clock.now as a reference point, rather than passing the reference explicitly.

Link copied to clipboard
fun <T> PolyglotReferenceValueLocalizer<T>.localizeAsFlow(value: T, clock: Clock = Clock.System, maxTick: Duration? = null): Flow<String>

Localizes value by using the given clock's Clock.now as a reference point and returns a Flow that emits updated values based on the underlying TickingValue.nextTick. This function assumes that the given clock moves forward linearly.

Link copied to clipboard
fun localizeDiff(diff: Int): String

Convenience function to format an already calculated diff of months (e.g. -1 for last month).