]> uap-core.de Git - rssreader.git/commitdiff
fix difference in behavior between item cleanup and item age filter
authorOlaf Wintermann <olaf.wintermann@gmail.com>
Fri, 5 Jun 2026 09:10:58 +0000 (11:10 +0200)
committerOlaf Wintermann <olaf.wintermann@gmail.com>
Fri, 5 Jun 2026 09:10:58 +0000 (11:10 +0200)
rss-application/src/main/kotlin/de/unixwork/rssreader/SyncJob.kt

index 62506fe8926143088815986332866d8154144630..6c9b70a55ef4a3dcb84b6ccc46cc72ab861dbaf7 100644 (file)
@@ -3,20 +3,17 @@ package de.unixwork.rssreader
 import com.rometools.rome.io.SyndFeedInput
 import com.rometools.rome.io.XmlReader
 import de.unixwork.ui.kotlin.ToolkitDispatcher
-import kotlinx.coroutines.Dispatchers
-import kotlinx.coroutines.GlobalScope
-import kotlinx.coroutines.IO
-import kotlinx.coroutines.async
-import kotlinx.coroutines.awaitAll
-import kotlinx.coroutines.coroutineScope
-import kotlinx.coroutines.launch
-import kotlinx.coroutines.runBlocking
+import kotlinx.coroutines.*
 import java.net.URI
 import java.net.http.HttpClient
 import java.net.http.HttpRequest
 import java.net.http.HttpResponse
-import java.time.Duration
 import java.time.Instant
+import java.time.LocalDate
+import java.time.ZoneId
+import java.time.ZoneOffset
+import java.time.temporal.ChronoUnit
+
 
 class SyncJob(settings: Settings, feeds: () -> List<Feed>) {
     val settings = settings
@@ -65,6 +62,7 @@ class SyncJob(settings: Settings, feeds: () -> List<Feed>) {
                                 val input = SyndFeedInput()
                                 val syndFeed = input.build(XmlReader(stream))
                                 val items = mutableListOf<Item>()
+                                val utcNow = Instant.now().atZone(ZoneOffset.UTC).toLocalDate()
                                 println("Fetched feed: ${syndFeed.title}")
                                 syndFeed.entries.forEach { entry ->
                                     //println("  ${entry.title} - ${entry.link}")
@@ -73,7 +71,8 @@ class SyncJob(settings: Settings, feeds: () -> List<Feed>) {
                                         if(max_age > 0) {
                                             val date = entry.updatedDate ?: entry.publishedDate
                                             date?.let {
-                                                val age = Duration.between(it.toInstant(), Instant.now()).toDays()
+                                                val localDate = it.toInstant().atZone(ZoneOffset.UTC).toLocalDate()
+                                                val age = ChronoUnit.DAYS.between(localDate,utcNow)
                                                 if(age > max_age) {
                                                     //println("Item too old, skipping: ${entry.title}  date: ${it}")
                                                     return@forEach