improving the UI of section date time

This commit is contained in:
tibbi 2020-04-03 23:18:53 +02:00
parent 59c5d16f62
commit a9ba3ada0c
5 changed files with 15 additions and 21 deletions

View file

@ -7,14 +7,8 @@ import android.text.format.Time
import com.simplemobiletools.commons.extensions.getTimeFormat
import java.util.*
fun Int.formatTime(context: Context): String {
val cal = Calendar.getInstance(Locale.ENGLISH)
cal.timeInMillis = this * 1000L
return DateFormat.format("${context.getTimeFormat()}", cal).toString()
}
// if the given date is today, we show only the time. Else we show only the date
fun Int.formatDateOrTime(context: Context): String {
fun Int.formatDateOrTime(context: Context, hideTimeAtOtherDays: Boolean): String {
val cal = Calendar.getInstance(Locale.ENGLISH)
cal.timeInMillis = this * 1000L
@ -26,6 +20,10 @@ fun Int.formatDateOrTime(context: Context): String {
format = format.replace("y", "").trim().trim('-').trim('.').trim('/')
}
if (!hideTimeAtOtherDays) {
format += ", ${context.getTimeFormat()}"
}
DateFormat.format(format, cal).toString()
}
}