Skip to content

Commit

Permalink
Fix iOS rss mapper not picking correct date formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
msasikanth committed Oct 16, 2023
1 parent 6ab15f4 commit aef2880
Showing 1 changed file with 4 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ import dev.sasikanth.rss.reader.network.FeedParser.Companion.TAG_IMAGE_URL
import dev.sasikanth.rss.reader.network.FeedParser.Companion.TAG_LINK
import dev.sasikanth.rss.reader.network.FeedParser.Companion.TAG_PUB_DATE
import dev.sasikanth.rss.reader.network.FeedParser.Companion.TAG_TITLE
import io.github.aakira.napier.Napier
import io.ktor.http.Url
import io.sentry.kotlin.multiplatform.Sentry
import platform.Foundation.NSDateFormatter
import platform.Foundation.NSLocale
import platform.Foundation.timeIntervalSince1970
Expand Down Expand Up @@ -109,17 +107,13 @@ internal fun FeedPayload.Companion.mapRssFeed(
private fun String?.rssDateStringToEpochSeconds(): Long {
if (this.isNullOrBlank()) return 0L

val dateString = this.trim()
val date =
try {
offsetTimezoneDateFormatter.dateFromString(this.trim())
offsetTimezoneDateFormatter.dateFromString(dateString)
?: abbrevTimezoneDateFormatter.dateFromString(dateString)
} catch (e: Exception) {
try {
abbrevTimezoneDateFormatter.dateFromString(this.trim())
} catch (e: Exception) {
Sentry.captureException(e)
Napier.e("Parse date error: ${e.message}")
null
}
null
}

return date?.timeIntervalSince1970?.times(1000)?.toLong() ?: 0L
Expand Down

0 comments on commit aef2880

Please sign in to comment.