Skip to content

Commit

Permalink
refactor: Rename formatPastDate into defaultFormatting for a more pre…
Browse files Browse the repository at this point in the history
…cision namming

The method does format future dates in a specific way so it can't be called "formatPastDate"
  • Loading branch information
LunarX committed Feb 17, 2025
1 parent d935019 commit 7b30541
Showing 1 changed file with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,23 @@ import java.util.Date
enum class DateDisplay(@DrawableRes val icon: Int?, val formatDate: Context.(RealmInstant) -> String) {
Default(
icon = null,
formatDate = { date -> formatPastDate(date) }
formatDate = { date -> defaultFormatting(date) }
),
Scheduled(
icon = R.drawable.ic_scheduled_messages,
formatDate = { date -> formatRelativeFutureDate(date) }
formatDate = { date -> relativeFormatting(date) }
),
}

private fun Context.formatRelativeFutureDate(date: RealmInstant) = DateUtils.getRelativeDateTimeString(
private fun Context.relativeFormatting(date: RealmInstant) = DateUtils.getRelativeDateTimeString(
this,
date.epochSeconds * 1000,
DateUtils.DAY_IN_MILLIS,
DateUtils.WEEK_IN_MILLIS,
DateUtils.FORMAT_SHOW_YEAR or DateUtils.FORMAT_ABBREV_MONTH,
)?.toString() ?: ""

private fun Context.formatPastDate(date: RealmInstant) = with(date.toDate()) {
private fun Context.defaultFormatting(date: RealmInstant) = with(date.toDate()) {
when {
isInTheFuture() -> formatNumericalDayMonthYear()
isToday() -> format(FORMAT_DATE_HOUR_MINUTE)
Expand Down

0 comments on commit 7b30541

Please sign in to comment.