Hi Robert, hope you are doing well! Is there suppo...
# kvision
j
Hi Robert, hope you are doing well! Is there support for datetime including local?
r
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
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
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