DynamicZonedYearLocalizer

Localizes a Zoned year (Zoned<Int>) dynamically (either absolute or relative to a Zoned<Instant> reference point).

This behaves identically to DynamicYearLocalizer, but it also adds a TimeZone in the mix (only in the absolute case).

This class chooses between formatting with a RelativeYearLocalizer (if the difference is within the configured range), or falls back to absolute formatting via ZonedYearLocalizer. Note that in case of relative localization, the relative value will always be calculated using the reference's time zone and behave exactly the same as RelativeYearLocalizer.

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

Because kotlinx-datetime doesn't provide a standard type for a year, there is no extension function equivalent for one-off localizations.

Examples:

  • last year, Los Angeles Time

  • 1 year ago, PT

  • in 5y, Pacific Time

  • 2026, Los Angeles Time

  • 2026 AD, Pacific Time

See also

Constructors

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

Functions

Link copied to clipboard
open override fun localize(value: Zoned<Int>, reference: Zoned<Instant>): TickingValue<String>
Link copied to clipboard
fun <T, R> PolyglotReferenceValueLocalizer<T, R>.localizeAsFlow(value: T, clock: Flow<ClockWrapper> = SYSTEM_CLOCK, timeZone: Flow<TimeZone> = SYSTEM_TIMEZONE, maxTick: Duration? = null): Flow<R>

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

Link copied to clipboard
fun <T, R> PolyglotReferenceValueLocalizer<T, R>.localizeNow(value: T, clock: Clock = Clock.System, timeZone: TimeZone = TimeZone.currentSystemDefault()): TickingValue<R>

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

Link copied to clipboard

Returns a new PolyglotReferenceValueLocalizer that localizes the received value using this localizer, calls map, and returns whatever TickingValue the mapping function returns.

Link copied to clipboard