feat(core-locale): relativeTimeAgo
This commit is contained in:
1 parent
71212c49d2
commit
d4970ba2bc
3 files changed
+21
-1
No files matched your search
@@ -0,0 +1,17 @@
|
||||
package de.jeanlucmakiola.floret.locale
|
||||
|
||||
import android.text.format.DateUtils
|
||||
|
||||
/**
|
||||
* "5 minutes ago" / "in 2 hours" for [epochMillis] relative to [nowMillis], in the
|
||||
* process locale, via the platform's `DateUtils`. Spans shorter than
|
||||
* [minResolution] read as the smallest unit ("0 minutes ago"), so a status line
|
||||
* doesn't tick by the second.
|
||||
*
|
||||
* Needs a real Android runtime, like [localizedDateFormatter].
|
||||
*/
|
||||
fun relativeTimeAgo(
|
||||
epochMillis: Long,
|
||||
nowMillis: Long = System.currentTimeMillis(),
|
||||
minResolution: Long = DateUtils.MINUTE_IN_MILLIS,
|
||||
): String = DateUtils.getRelativeTimeSpanString(epochMillis, nowMillis, minResolution).toString()
|
||||
Reference in new issue
Block a user