RelativeTimeSpanStringResolver

data class RelativeTimeSpanStringResolver(time: Instant, updateDurationMs: Long = DEFAULT_UPDATE_DURATION_MS) : FlowStringResolver

A StringResolver that takes a time and resolves it to a String representation that shows the relative time.

When the instant of time represented by time is:

  • Within the last/next minute, shows: now.

  • Within the last/next hour shows: __ min(s) ago or in __ min(s). For example: 31 mins ago for an instant of time 31 mins ago.

  • More than an hour in the past or in the future, but within 24 hours of the current time, shows: __ hr(s) ago or in __ hr(s). For example: 2 hrs ago for a time 2 hours 59 mins ago.

  • Yesterday/tomorrow shows the time in HH:mm or h:m format with optionally AM/PM based on the locale. For example: 23:13 for a time tomorrow at 23 hours 13 mins.

  • Within the last/next 7 days, shows the day of the week. For example: Monday for a time 7 days in the future.

  • More than 7 days in the past/future, shows the date without the year. For example: 21 March.

  • More than a year in the past/future, shows the date with the year. For example: 21 March 2021.

Parameters

time

The instant of time to calculate the relative time from.

updateDurationMs

indicates how often the underlying string should be updated.

Constructors

Link copied to clipboard
fun RelativeTimeSpanStringResolver(time: Instant, updateDurationMs: Long = DEFAULT_UPDATE_DURATION_MS)

Types

Link copied to clipboard
object Companion

Functions

Link copied to clipboard
open override fun get(context: Context): String

Resolves a String based on the given Context. The resulting value may differ per Context. E.g. due to differing locales.

Link copied to clipboard
open override fun getFlow(context: Context): Flow<String>

Get a Flow which will emit Strings using the given Context. The resulting values may differ per Context. E.g. due to differing locales.

Inherited functions

Link copied to clipboard
abstract fun describeContents(): Int
Link copied to clipboard
abstract fun writeToParcel(p0: Parcel, p1: Int)