https://kotlinlang.org logo
#kvision
Title
# kvision
j

Jörg Rade

02/29/2024, 1:16 PM
Hi Robert, hope you are doing well! Is there support for datetime including local?
r

Robert Jaros

02/29/2024, 1:28 PM
Hi, On the frontend side only JS
Date
is used.
If you are using fullstack, you can use datetime types which are mapped to java.time.* in the backend code.
👍 1
j

Jörg Rade

03/01/2024, 12:14 PM
What I have in mind is something like this:
Copy code
import kotlinx.browser.document
import org.w3c.dom.HTMLInputElement

fun main() {
    val hoursInput = document.getElementById("hoursInput") as HTMLInputElement
    val minutesInput = document.getElementById("minutesInput") as HTMLInputElement
    val secondsInput = document.getElementById("secondsInput") as HTMLInputElement
    val timestampDisplay = document.getElementById("timestampDisplay")

    hoursInput.addEventListener("input", ::updateTimestamp)
    minutesInput.addEventListener("input", ::updateTimestamp)
    secondsInput.addEventListener("input", ::updateTimestamp)

    updateTimestamp()
}

fun updateTimestamp() {
    val hours = (document.getElementById("hoursInput") as HTMLInputElement).value.padStart(2, '0')
    val minutes = (document.getElementById("minutesInput") as HTMLInputElement).value.padStart(2, '0')
    val seconds = (document.getElementById("secondsInput") as HTMLInputElement).value.padStart(2, '0')

    val timestamp = "$hours:$minutes:$seconds"
    document.getElementById("timestampDisplay")?.textContent = timestamp
}
At which points could i make better use of KVision?
r

Robert Jaros

03/01/2024, 12:17 PM
I think what you need is kotlinx-datetime (perhaps even with this extension lib https://github.com/RaedGhazal/kotlinx-datetime-ext). You can easily use this with KVision (or any other Kotlin/JS app) just to process date/time values.
🙏 1
❤️ 1
2 Views