RelativeLocalDateLocalizer

class RelativeLocalDateLocalizer(options: RelativeLocalDateOptions = RelativeLocalDateOptions(), val locale: PlatformLocale = getDefaultLocale()) : PolyglotReferenceValueLocalizer<LocalDate> (source)

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

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

Localization prioritizes, based on options:

  • word style localization (e.g. yesterday, today, tomorrow, etc.)

  • day of week relative localization (e.g. this Friday or next Monday)

  • numeric style (e.g. in 15 days)

Important note on day of week relative localization: given that this form of localization is sometimes ambiguous, it is bound be the following rules:

  • last <day-of-week> form is never used, because it could lead to ambiguity (e.g. if the reference is Wednesday, and the output is last Monday, does it mean 2 days ago or 9 days ago?)

  • this <day-of-week> is used when the day in question is in the future and falls in the same week (according to the PlatformLocale)

  • next <day-of-week> is used when the day in question is in the future, falls in the next week (according to the PlatformLocale), and is within 7 days of the reference. This means that, next <day-of-week> can never be produced if the reference point is at a day of week earlier than <day-of-week> (according to the PlatformLocale). As a clarification example, imagine that we are using the en-GB locale (where the first day of the week is Monday), and the reference is Wednesday. Only the following localizations can be produced using this format:

    • this Thursday (1 day in the future)

    • this Friday (2 days in the future)

    • this Saturday (3 days in the future)

    • this Sunday (4 days in the future)

    • next Monday (5 days in the future)

    • next Tuesday (6 days in the future)

    • next Wednesday (7 days in the future)

Notice how in the example next Thursday cannot be produced because it would be ambiguous (does it mean in 1 day or in 8 days?). In this case it would fall back to the regular numeric relative format (i.e. in 8 days).

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

Examples:

  • today

  • yesteday

  • tomorrow

  • this Monday

  • next Friday

  • in 54 days

  • 5 days ago

See also

Constructors

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

Properties

Link copied to clipboard

Functions

Link copied to clipboard
open override fun localize(value: LocalDate, 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.