Skip to content

Commit b21a11a

Browse files
committed
Get setting date with kotlinx-datetime to work
ref: huanshankeji#1
1 parent 9cf28f1 commit b21a11a

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import io.vertx.sqlclient.RowSet
1919
import io.vertx.sqlclient.Tuple
2020
import kotlinx.coroutines.Dispatchers
2121
import kotlinx.datetime.TimeZone
22+
import kotlinx.datetime.UtcOffset
2223
import kotlinx.datetime.format.DateTimeComponents
2324
import kotlinx.datetime.format.format
2425
import kotlinx.datetime.toLocalDateTime
@@ -33,10 +34,6 @@ import kotlinx.serialization.json.io.encodeToSink
3334
import kotlin.time.Clock
3435

3536
class MainVerticle(val hasDb: Boolean) : CoroutineVerticle(), CoroutineRouterSupport {
36-
companion object {
37-
val timeZone = TimeZone.currentSystemDefault()
38-
}
39-
4037
// `PgConnection`s as used in the "vertx" portion offers better performance than `PgPool`s.
4138
lateinit var pgConnection: PgConnection
4239
lateinit var date: String
@@ -48,7 +45,8 @@ class MainVerticle(val hasDb: Boolean) : CoroutineVerticle(), CoroutineRouterSup
4845

4946
fun setCurrentDate() {
5047
date = DateTimeComponents.Formats.RFC_1123.format {
51-
setDateTime(Clock.System.now().toLocalDateTime(timeZone))
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)
5250
}
5351
}
5452

0 commit comments

Comments
 (0)