RelativeInstantLocalizer

class RelativeInstantLocalizer(options: RelativeInstantOptions = RelativeInstantOptions(), locale: PlatformLocale = getDefaultLocale()) : PolyglotReferenceValueLocalizer<Instant> (source)

Localizes an Instant relative to another one.

This class is a simple convenience over RelativeDurationLocalizer, simply calculating the diff and forwarding the localization request to it. As this implements PolyglotReferenceValueLocalizer, this allows to use localizeAsFlow.

For this reason, the options required here are identical to RelativeDurationLocalizer.

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

Examples:

  • 10 minutes ago

  • in 1 hour

  • 4h ago

  • 4 hr. ago

  • in 2 days

See also

Constructors

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

Functions

Link copied to clipboard
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.