TimeAgo

object TimeAgo

TimeAgo is an Object that converts a date into a humanized text. Instead of showing a date 2020-12-12 18:30 with timeago you can display something like "now", "an hour ago", "~1y", etc

Note: This class uses ISO 639-1 language code to identify the language. For more information see ISO 639-1.

Example:

TimeAgo.setDefaultLocale("fa")
TimeAgo.format(now()) // "چند لحظه پیش"

Since

1.1.0

See also

Types

Link copied to clipboard
object Locale

Locale show available languages for TimeAgo.

Properties

Link copied to clipboard
val default: String
Link copied to clipboard
@JvmField
var isLocaleNumberEnabled: Boolean

Functions

Link copied to clipboard
@JvmStatic
@JvmOverloads
fun format(date: Calendar, locale: String = default, clock: Calendar = nowInCalendar(), minCutOff: DateLimitation = None, isWeekFormatEnabled: Boolean = false, allowFromNow: Boolean = false): String
@JvmStatic
@JvmOverloads
fun format(date: Date, locale: String = default, clock: Date = nowInDate(), minCutOff: DateLimitation = None, isWeekFormatEnabled: Boolean = false, allowFromNow: Boolean = false): String
@JvmStatic
@JvmOverloads
fun format(date: Long, locale: String = default, clock: Long = nowInMilliseconds(), minCutOff: DateLimitation = None, isWeekFormatEnabled: Boolean = false, allowFromNow: Boolean = false): String
@JvmStatic
@JvmOverloads
fun format(date: Instant, locale: String = default, clock: Instant = now(), minCutOff: DateLimitation = None, isWeekFormatEnabled: Boolean = false, allowFromNow: Boolean = false): String
@JvmStatic
@JvmOverloads
fun format(date: LocalDateTime, locale: String = default, clock: LocalDateTime = nowInLocalDateTime(), minCutOff: DateLimitation = None, isWeekFormatEnabled: Boolean = false, allowFromNow: Boolean = false): String

Formats provided date to a fuzzy time like 'a moment ago'.

Link copied to clipboard
@JvmStatic
fun setDefaultLocale(locale: String)

Sets the default locale. By default, it is en.

Link copied to clipboard
@JvmStatic
fun setLocaleMessages(vararg locales: String)

Sets locales with the auto provided LookupMessages to be available when using the format function.

@JvmStatic
fun setLocaleMessages(locale: String)

Sets a locale with the auto provided LookupMessages to be available when using the format function.

@JvmStatic
fun setLocaleMessages(locale: String, lookupMessages: LookupMessages)

Sets a locale with the provided lookupMessages to be available when using the format function.

Link copied to clipboard
@JvmStatic
fun setLocaleMessagesAndDefaultLocale(locale: String)
@JvmStatic
fun setLocaleMessagesAndDefaultLocale(locale: String, lookupMessages: LookupMessages)

Sets a locale with the auto provided LookupMessages to be available when using the format function. also Sets the default locale.