]> uap-core.de Git - rssreader.git/commitdiff
use UTC internally
authorOlaf Wintermann <olaf.wintermann@gmail.com>
Mon, 8 Sep 2025 06:53:34 +0000 (08:53 +0200)
committerOlaf Wintermann <olaf.wintermann@gmail.com>
Mon, 8 Sep 2025 06:53:34 +0000 (08:53 +0200)
rss-application/src/main/kotlin/de/unixwork/rssreader/Database.kt
rss-application/src/main/kotlin/de/unixwork/rssreader/Feed.kt
rss-application/src/main/kotlin/de/unixwork/rssreader/Item.kt
rss-application/src/main/kotlin/de/unixwork/rssreader/MainWindow.kt
rss-application/src/main/kotlin/de/unixwork/rssreader/SyncJob.kt

index 54f18ab5a417a7fccd3ec3befccf53be64f312f4..4461840a1603acb260c89b05b314a2a7884c8270 100644 (file)
@@ -18,7 +18,7 @@ object Database {
 
     init {
         val config = HikariConfig()
-        config.jdbcUrl = "jdbc:h2:~/.rssreader/feeds"
+        config.jdbcUrl = "jdbc:h2:~/.rssreader/feeds;TIME ZONE=UTC"
         config.maximumPoolSize = 16
         dataSource = HikariDataSource(config)
 
@@ -251,8 +251,8 @@ object Database {
                         item.category = rs.getString("category")
                         item.description = rs.getString("description")
                         item.author = rs.getString("author")
-                        item.pubDate = rs.getObject("pub_date", java.time.LocalDateTime::class.java)
-                        item.updated = rs.getObject("updated", java.time.LocalDateTime::class.java)
+                        item.pubDate = rs.getTimestamp("pub_date")?.toInstant();
+                        item.updated = rs.getTimestamp("updated")?.toInstant();
                         item.guid = rs.getString("guid")
                         item.contentText = rs.getString("contentText")
                         item.contentHtml = rs.getString("contentHTML")
@@ -355,8 +355,8 @@ object Database {
                     stmt.setString(4, item.category)
                     stmt.setString(5, item.description)
                     stmt.setString(6, item.author)
-                    stmt.setTimestamp(7, item.pubDate?.let { java.sql.Timestamp.valueOf(it) })
-                    stmt.setTimestamp(8, item.updated?.let { java.sql.Timestamp.valueOf(it) })
+                    stmt.setTimestamp(7, item.pubDate?.let { java.sql.Timestamp.from(it) })
+                    stmt.setTimestamp(8, item.updated?.let { java.sql.Timestamp.from(it) })
                     stmt.setString(9, item.guid)
                     stmt.setString(10, item.contentText)
                     stmt.setString(11, item.contentHtml)
@@ -381,7 +381,7 @@ object Database {
 
     public fun updateFeedDate(feed: Feed) {
         dataSource.connection.use { conn ->
-            feed.lastUpdate = java.time.LocalDateTime.now()
+            feed.lastUpdate = java.time.Instant.now()
             conn.prepareStatement("""
                 update feeds set last_update = now() where feed_id = ?
             """.trimIndent()).use { stmt ->
index d6e7db2074e4d292723a970e8c89e1487d887d0c..e952d26c3508b5a549966553f2077b99d00cffcf 100644 (file)
@@ -1,6 +1,6 @@
 package de.unixwork.rssreader
 
-import java.time.LocalDateTime
+import java.time.Instant
 
 
 class Feed(id: Int, feedCollectionId: Int, uri: String) {
@@ -10,5 +10,5 @@ class Feed(id: Int, feedCollectionId: Int, uri: String) {
     var user: String? = null
     var password: String? = null
     var certpath: String? = null
-    var lastUpdate: LocalDateTime? = null
+    var lastUpdate: Instant? = null
 }
index 33758edd524ea0868c812ec8cc03f5533b33528b..15e90edb3b52b5c2b36b172db9b03965473f3358 100644 (file)
@@ -1,6 +1,6 @@
 package de.unixwork.rssreader
 
-import java.time.LocalDateTime
+import java.time.Instant
 
 
 class Item(id: Int) {
@@ -11,8 +11,8 @@ class Item(id: Int) {
     var category: String? = null
     var description: String? = null
     var author: String? = null
-    var pubDate: LocalDateTime? = null
-    var updated: LocalDateTime? = null
+    var pubDate: Instant? = null
+    var updated: Instant? = null
     var guid: String? = null
     var contentText: String? = null
     var contentHtml: String? = null
index 7cbb3f6d35a1d51b8d323fba10348a00eceeb5fd..8b1acac50c1d5509ae7e3677b42a308892de34e8 100644 (file)
@@ -12,6 +12,7 @@ import de.unixwork.ui.kotlin.Toplevel
 import de.unixwork.ui.kotlin.sidebarWindow
 import de.unixwork.ui.kotlin.dialogWindow
 import de.unixwork.ui.kotlin.openFileDialog
+import java.time.ZoneId
 import java.time.format.DateTimeFormatter
 
 class MainWindow {
@@ -20,7 +21,7 @@ class MainWindow {
     val feedList = FeedList()
 
     // TODO: date format config
-    val formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")
+    val formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss").withZone(ZoneId.systemDefault())
 
     var newFeedPrevGroup = 0
 
@@ -107,7 +108,7 @@ class MainWindow {
                         var result: String? = null
                         when(col) {
                             0 -> result = elm.title
-                            1 -> result = elm.updated?.format(formatter) ?: elm.pubDate?.format(formatter)
+                            1 -> result = formatter.format(elm.updated ?: elm.pubDate)
                         }
                         result
                     }
index 120bacda95cb7796773305dd04eb20d95e616b1d..00dfda29b0fee01011a84df5e64b755965855578 100644 (file)
@@ -72,10 +72,10 @@ class SyncJob(feeds: () -> List<Feed>) {
                                 item.description = entry.description?.value
                                 item.author = entry.author
                                 entry.publishedDate?.let {
-                                    item.pubDate = it.toInstant().atZone(java.time.ZoneId.systemDefault()).toLocalDateTime()
+                                    item.pubDate = it.toInstant()
                                 }
                                 entry.updatedDate?.let {
-                                    item.updated = it.toInstant().atZone(java.time.ZoneId.systemDefault()).toLocalDateTime()
+                                    item.updated = it.toInstant()
                                 }
                                 item.guid = entry.uri
                                 val contents = entry.contents