RelativeZonedYearLocalizer

class RelativeZonedYearLocalizer(options: RelativeZonedYearOptions = RelativeZonedYearOptions(), locale: PlatformLocale = getDefaultLocale()) : PolyglotReferenceValueLocalizer<Zoned<Int>> (source)

Localizes a Zoned year (Zoned<Int) relative to a Zoned<Instant> reference point.

This behaves identically to RelativeYearLocalizer, but it also adds a TimeZone in the mix. Note that the localized value is always relative to the reference time zone: the value's time zone is simply added in output, but it does not affect relative calculations.

Because a year represents a big span of time, the timezone could have different offsets at different moments within the year. For this reason, only the TimeZoneStyle.Generic subset is allowed in the options for the time zone style.

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 yr., Los Angeles Time

  • this year, PT

  • 1 year ago, Pacific Time

  • in 5y, America/Los_Angeles

See also

Constructors

Link copied to clipboard
constructor(options: RelativeZonedYearOptions = RelativeZonedYearOptions(), 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> 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.