Format time

This commit is contained in:
Kgothatso Ngako
2026-03-30 13:09:49 +02:00
parent 9fade17836
commit 4cce9bc3d4
4 changed files with 31 additions and 1 deletions

View File

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

View File

@@ -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()
}
)
}

View File

@@ -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()
)
}
}

View File

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