Skip to content

Commit d084060

Browse files
committed
Merge branch 'vertx-web-kotlinx-update-dec-2025-use-kotlinx-datetime' into vertx-web-kotlinx-update-dec-2025
2 parents 8edf0a6 + b21a11a commit d084060

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

frameworks/Kotlin/vertx-web-kotlinx/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ dependencies {
3131
implementation("org.jetbrains.kotlinx:kotlinx-io-core:0.8.2")
3232

3333
implementation("org.jetbrains.kotlinx:kotlinx-html:0.12.0")
34-
//implementation("org.jetbrains.kotlinx:kotlinx-datetime:0.7.1")
34+
implementation("org.jetbrains.kotlinx:kotlinx-datetime:0.7.1")
3535
}
3636

3737
kotlin.jvmToolchain(25) // Kotlin doesn't support Java 25 yet

frameworks/Kotlin/vertx-web-kotlinx/src/main/kotlin/MainVerticle.kt

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ import io.vertx.sqlclient.Row
1818
import io.vertx.sqlclient.RowSet
1919
import io.vertx.sqlclient.Tuple
2020
import kotlinx.coroutines.Dispatchers
21+
import kotlinx.datetime.TimeZone
22+
import kotlinx.datetime.UtcOffset
23+
import kotlinx.datetime.format.DateTimeComponents
24+
import kotlinx.datetime.format.format
25+
import kotlinx.datetime.toLocalDateTime
2126
import kotlinx.html.*
2227
import kotlinx.html.stream.appendHTML
2328
import kotlinx.io.buffered
@@ -26,8 +31,7 @@ import kotlinx.serialization.Serializable
2631
import kotlinx.serialization.SerializationStrategy
2732
import kotlinx.serialization.json.Json
2833
import kotlinx.serialization.json.io.encodeToSink
29-
import java.time.ZonedDateTime
30-
import java.time.format.DateTimeFormatter
34+
import kotlin.time.Clock
3135

3236
class MainVerticle(val hasDb: Boolean) : CoroutineVerticle(), CoroutineRouterSupport {
3337
// `PgConnection`s as used in the "vertx" portion offers better performance than `PgPool`s.
@@ -40,9 +44,10 @@ class MainVerticle(val hasDb: Boolean) : CoroutineVerticle(), CoroutineRouterSup
4044
lateinit var updateWordQuery: PreparedQuery<RowSet<Row>>
4145

4246
fun setCurrentDate() {
43-
// Don't know how to get kotlinx-datetime to work here properly. See commit 9cf28f15b6f1806b3ed75260adee8acd822cac91 for a failed attempt.
44-
//date = Clock.System.now().toString()
45-
date = DateTimeFormatter.RFC_1123_DATE_TIME.format(ZonedDateTime.now())
47+
date = DateTimeComponents.Formats.RFC_1123.format {
48+
// We don't need a more complicated system `TimeZone` here (whose offset depends dynamically on the actual time due to DST) since UTC works.
49+
setDateTimeOffset(Clock.System.now(), UtcOffset.ZERO)
50+
}
4651
}
4752

4853
override suspend fun start() {

0 commit comments

Comments
 (0)