Global date formatter.

This commit is contained in:
davidoskky 2021-03-19 20:51:59 +01:00
parent f4f8503037
commit 9b372a45ce
3 changed files with 4 additions and 8 deletions

View File

@ -109,7 +109,6 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener {
private var periodicRefresh = false private var periodicRefresh = false
private var refreshMinutes: Long = 360L private var refreshMinutes: Long = 360L
private var refreshWhenChargingOnly = false private var refreshWhenChargingOnly = false
private var dateTimeFormatter = "yyyy-MM-dd HH:mm:ss"
private lateinit var tabNewBadge: TextBadgeItem private lateinit var tabNewBadge: TextBadgeItem
private lateinit var tabArchiveBadge: TextBadgeItem private lateinit var tabArchiveBadge: TextBadgeItem

View File

@ -18,6 +18,8 @@ import com.mikepenz.materialdrawer.util.AbstractDrawerImageLoader
import com.mikepenz.materialdrawer.util.DrawerImageLoader import com.mikepenz.materialdrawer.util.DrawerImageLoader
import java.util.UUID.randomUUID import java.util.UUID.randomUUID
var dateTimeFormatter = "yyyy-MM-dd HH:mm:ss"
class MyApp : MultiDexApplication() { class MyApp : MultiDexApplication() {
private lateinit var config: Config private lateinit var config: Config

View File

@ -4,6 +4,7 @@ import android.content.Context
import android.text.format.DateUtils import android.text.format.DateUtils
import apps.amine.bou.readerforselfoss.api.selfoss.Item import apps.amine.bou.readerforselfoss.api.selfoss.Item
import apps.amine.bou.readerforselfoss.api.selfoss.SelfossTagType import apps.amine.bou.readerforselfoss.api.selfoss.SelfossTagType
import apps.amine.bou.readerforselfoss.dateTimeFormatter
import java.text.ParseException import java.text.ParseException
import java.text.SimpleDateFormat import java.text.SimpleDateFormat
import java.util.* import java.util.*
@ -21,14 +22,8 @@ fun String.toTextDrawableString(c: Context): String {
fun Item.sourceAndDateText(): String { fun Item.sourceAndDateText(): String {
val formattedDate: String = try { val formattedDate: String = try {
var date = SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(this.datetime)
// Api 3.0 changes the date format, check for ISO8601 format
if (date == null) {
date = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssXXX").parse(this.datetime)
}
" " + DateUtils.getRelativeTimeSpanString( " " + DateUtils.getRelativeTimeSpanString(
date.time, SimpleDateFormat(dateTimeFormatter).parse(this.datetime).time,
Date().time, Date().time,
DateUtils.MINUTE_IN_MILLIS, DateUtils.MINUTE_IN_MILLIS,
DateUtils.FORMAT_ABBREV_RELATIVE DateUtils.FORMAT_ABBREV_RELATIVE