diff --git a/composeApp/build.gradle.kts b/composeApp/build.gradle.kts index a21d65c5..4ed1f907 100644 --- a/composeApp/build.gradle.kts +++ b/composeApp/build.gradle.kts @@ -68,6 +68,9 @@ kotlin { implementation("com.vitorpamplona.quartz:quartz:1.05.1") + + implementation(libs.kotlinx.datetime) + implementation(libs.ktor.client.core) implementation("io.ktor:ktor-client-websockets:3.4.1") implementation("io.ktor:ktor-serialization-kotlinx-json:3.4.1") diff --git a/composeApp/src/commonMain/kotlin/ac/aux/compose/extensions/Instant.kt b/composeApp/src/commonMain/kotlin/ac/aux/compose/extensions/Instant.kt new file mode 100644 index 00000000..c3c9d0e2 --- /dev/null +++ b/composeApp/src/commonMain/kotlin/ac/aux/compose/extensions/Instant.kt @@ -0,0 +1,24 @@ +package ac.aux.compose.extensions + +import kotlinx.datetime.LocalDateTime +import kotlinx.datetime.TimeZone +import kotlinx.datetime.format +import kotlinx.datetime.format.char +import kotlinx.datetime.toLocalDateTime +import kotlin.time.Instant + +fun Instant.toFormattedTimeAndDateString(): String { + return toLocalDateTime(TimeZone.currentSystemDefault()).format( + LocalDateTime.Format { + year() + char('-') + monthNumber() + char('-') + day() + char(' ') + hour() + char(':') + minute() + } + ) +} \ No newline at end of file diff --git a/composeApp/src/commonMain/kotlin/ac/aux/compose/ui/composable/widgets/feed/EventListView.kt b/composeApp/src/commonMain/kotlin/ac/aux/compose/ui/composable/widgets/feed/EventListView.kt index f51377f6..2391beac 100644 --- a/composeApp/src/commonMain/kotlin/ac/aux/compose/ui/composable/widgets/feed/EventListView.kt +++ b/composeApp/src/commonMain/kotlin/ac/aux/compose/ui/composable/widgets/feed/EventListView.kt @@ -1,6 +1,7 @@ package ac.aux.compose.ui.composable.widgets.feed import ac.aux.compose.database.model.NostrEvent +import ac.aux.compose.extensions.toFormattedTimeAndDateString import ac.aux.compose.ui.theme.AuxTheme import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Column @@ -88,7 +89,7 @@ fun NostrEvent.ListView() { } Text( - text = createdAt.toString() + text = createdAt.toFormattedTimeAndDateString() ) } } diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index b88c3132..4ca7158b 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -15,6 +15,7 @@ junit = "4.13.2" kermit = "2.0.8" kotlin = "2.3.0" kotlinx-coroutines = "1.10.2" +kotlinx-datetime = "0.7.1" ksp = "2.3.6" ktor = "3.4.1" material3 = "1.10.0-alpha05" @@ -51,6 +52,7 @@ compose-components-resources = { module = "org.jetbrains.compose.components:comp compose-uiToolingPreview = { module = "org.jetbrains.compose.ui:ui-tooling-preview", version.ref = "composeMultiplatform" } kermit = { module = "co.touchlab:kermit", version.ref = "kermit" } kotlinx-coroutinesSwing = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-swing", version.ref = "kotlinx-coroutines" } +kotlinx-datetime = { module = "org.jetbrains.kotlinx:kotlinx-datetime", version.ref = "kotlinx-datetime" } ktor-client-core = { module = "io.ktor:ktor-client-core", version.ref = "ktor" } ktor-client-okhttp = { module = "io.ktor:ktor-client-okhttp", version.ref = "ktor" } ktor-client-darwin = { module = "io.ktor:ktor-client-darwin", version.ref = "ktor" }