improving the UI of section date time
This commit is contained in:
parent
59c5d16f62
commit
a9ba3ada0c
5 changed files with 15 additions and 21 deletions
|
|
@ -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()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue