TickingDurationLocalizer

Localizes a Duration in the same exact way as a DurationLocalizer, but this is meant to be used to localize duration values that change over time (e.g. a countdown). For static durations use DurationLocalizer instead.

The TickingValue.value will be the same as the output of Duration.localize.

For the purposes of TickingValue.nextTick, this class assumes that the given Duration is obtained from a computation that linearly "moves" backwards, i.e. a positive duration means something that will happen in the future, and a negative duration something that has happened in the past. For instance, if given the duration 10 seconds, this class assumes that in 1.5 seconds the Duration would be 8.5 seconds.

Create once and re-use for localizing multiple values with the same options. Use Duration.localizeTicking for one-off localizations.

Examples:

  • 1h 5m

  • 1 hr, 5 min

  • 1 hour, 5 minutes

Constructors

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

Functions

Link copied to clipboard
open override fun localize(value: Duration): TickingValue<String>
open override fun localize(value: Instant, reference: Zoned<Instant>): TickingValue<String>
fun localize(value: Instant, reference: 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.