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
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}")
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