timeAgo

fun Long.timeAgo(locale: String = TimeAgo.default, clock: Long = nowInMilliseconds(), minCutOff: DateLimitation = None, isWeekFormatEnabled: Boolean = false, allowFromNow: Boolean = false): String

Formats provided this value to a fuzzy time like 'a moment ago'.

  • If locale is passed will look for message for that locale, if you want to add or override locales use setLocaleMessages. Defaults to 'en'.

  • If clock is passed this will be the point of reference for calculating the elapsed time. Defaults to nowInMilliseconds

  • If minCutOff is passed from that date bellow all prefix and suffix disabled to show date without ago. Default value is None.

  • If isWeekFormatEnabled is true, week format enabled and show 7 days - 28 days as 1 week to 4 week.

  • If allowFromNow is true, format will use the Form prefix, i.e. a date 5 minutes from now in 'en' locale will display as "5 minutes from now".

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

1565591769464.timeAgo() // on 08/12/2019

Since

1.1.0


fun Date.timeAgo(locale: String = TimeAgo.default, clock: Date = nowInDate(), minCutOff: DateLimitation = None, isWeekFormatEnabled: Boolean = false, allowFromNow: Boolean = false): String

Formats provided this value to a fuzzy time like 'a moment ago'.

  • If locale is passed will look for message for that locale, if you want to add or override locales use setLocaleMessages. Defaults to 'en'.

  • If clock is passed this will be the point of reference for calculating the elapsed time. Defaults to nowInCalendar

  • If minCutOff is passed from that date bellow all prefix and suffix disabled to show date without ago. Default value is None.

  • If isWeekFormatEnabled is true, week format enabled and show 7 days - 28 days as 1 week to 4 week.

  • If allowFromNow is true, format will use the Form prefix, i.e. a date 5 minutes from now in 'en' locale will display as "5 minutes from now".

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

(nowInDate() - 4.hours).timeAgo() // 4 hours ago

Since

1.1.0


fun Calendar.timeAgo(locale: String = TimeAgo.default, clock: Calendar = nowInCalendar(), minCutOff: DateLimitation = None, isWeekFormatEnabled: Boolean = false, allowFromNow: Boolean = false): String

Formats provided this value to a fuzzy time like 'a moment ago'.

  • If locale is passed will look for message for that locale, if you want to add or override locales use setLocaleMessages. Defaults to 'en'.

  • If clock is passed this will be the point of reference for calculating the elapsed time. Defaults to nowInCalendar

  • If minCutOff is passed from that date bellow all prefix and suffix disabled to show date without ago. Default value is None.

  • If isWeekFormatEnabled is true, week format enabled and show 7 days - 28 days as 1 week to 4 week.

  • If allowFromNow is true, format will use the Form prefix, i.e. a date 5 minutes from now in 'en' locale will display as "5 minutes from now".

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

(nowInCalendar() - 1.hours).timeAgo() // about an hour ago

Since

1.1.0


fun Instant.timeAgo(locale: String = TimeAgo.default, clock: Instant = now(), minCutOff: DateLimitation = None, isWeekFormatEnabled: Boolean = false, allowFromNow: Boolean = false): String

Formats provided this value to a fuzzy time like 'a moment ago'.

  • If locale is passed will look for message for that locale, if you want to add or override locales use setLocaleMessages. Defaults to 'en'.

  • If clock is passed this will be the point of reference for calculating the elapsed time. Defaults to now

  • If minCutOff is passed from that date bellow all prefix and suffix disabled to show date without ago. Default value is None.

  • If isWeekFormatEnabled is true, week format enabled and show 7 days - 28 days as 1 week to 4 week.

  • If allowFromNow is true, format will use the Form prefix, i.e. a date 5 minutes from now in 'en' locale will display as "5 minutes from now".

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

now().timeAgo() // a moment ago

Since

1.1.0


fun LocalDateTime.timeAgo(locale: String = TimeAgo.default, clock: LocalDateTime = nowInLocalDateTime(), minCutOff: DateLimitation = None, isWeekFormatEnabled: Boolean = false, allowFromNow: Boolean = false): String

Formats provided this value to a fuzzy time like 'a moment ago'.

  • If locale is passed will look for message for that locale, if you want to add or override locales use setLocaleMessages. Defaults to 'en'.

  • If clock is passed this will be the point of reference for calculating the elapsed time. Defaults to nowInLocalDateTime

  • If minCutOff is passed from that date bellow all prefix and suffix disabled to show date without ago. Default value is None.

  • If isWeekFormatEnabled is true, week format enabled and show 7 days - 28 days as 1 week to 4 week.

  • If allowFromNow is true, format will use the Form prefix, i.e. a date 5 minutes from now in 'en' locale will display as "5 minutes from now".

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

(nowInLocalDateTime() - 1.years).timeAgo() // about a year ago

Since

1.1.0