Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ plugins {
id 'com.android.library' version '9.0.0' apply false
id 'org.jetbrains.kotlin.android' version "$kotlinVersion" apply false
id 'com.android.legacy-kapt' version '9.0.0' apply false
id 'com.diffplug.spotless' version '8.1.0' apply false
id 'com.diffplug.spotless' version '8.2.0' apply false
id 'io.gitlab.arturbosch.detekt' version '1.23.8' apply false
id 'com.android.application' version '9.0.0' apply false
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ class DateFormatter(
private val sdfMonths: SimpleDateFormat
private val sdfYears: SimpleDateFormat

/**
* constructor.
*/
init {
val locale =
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
Expand Down Expand Up @@ -59,26 +56,40 @@ class DateFormatter(
val span = System.currentTimeMillis() - calendar.getTimeInMillis()
return when {
// less than 1m
span < ONE_MINUTE_IN_MILLIS -> context.getString(R.string.date_formatting_now)
span < ONE_MINUTE_IN_MILLIS -> {
context.getString(R.string.date_formatting_now)
}

// less than 1h
span < ONE_HOUR_IN_MILLIS ->
span < ONE_HOUR_IN_MILLIS -> {
context.getString(
R.string.date_formatting_relative_minutes,
span / ONE_MINUTE_IN_MILLIS
)
}

// less than 1d
span < ONE_DAY_IN_MILLIS -> {
val hours: Int = span.toInt() / ONE_HOUR_IN_MILLIS
context
.resources
.getQuantityString(R.plurals.date_formatting_relative_hours, hours, hours)
}

// less than 1w
span <= SIX_DAYS_IN_MILLIS -> sdfDays.format(calendar.getTime())
span <= SIX_DAYS_IN_MILLIS -> {
sdfDays.format(calendar.getTime())
}

// less than 1y -> up to 364 days
span <= YEAR_IN_MILLIS -> sdfMonths.format(calendar.getTime())
span <= YEAR_IN_MILLIS -> {
sdfMonths.format(calendar.getTime())
}

// more than 1y -> more than 364 days
else -> sdfYears.format(calendar.getTime())
else -> {
sdfYears.format(calendar.getTime())
}
}
}

Expand Down
Loading
Loading