Thread
#multiplatform
    j

    janvladimirmostert

    2 years ago
    is there a Kotlin Multiplatform Date class? The one in https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.js/-date/ says it's supported on JVM, JS and Common, but not seeing anything when I Ctrl+Space in IntelliJ in a Common Module on 1.4 M2
    t

    Tijl

    2 years ago
    every method in your link is marked “js”, not common or jvm (aside from the fact it’s in a
    .js
    package)
    AFAIK there are only external libraries like Klock
    j

    janvladimirmostert

    2 years ago
    that's what i thought, strange that it's labelled Common, JS, JVM, Native when it's on a kotlin.js page
    t

    Tijl

    2 years ago
    it’s labeled js
    in my browser at least
    j

    janvladimirmostert

    2 years ago
    ah, i see now, the labels at the top is just the index, i need to look a the yellow dots next to the methods
    t

    Tijl

    2 years ago
    we use Klock for some things at my company (not me personally), didn’t hear any complaints
    j

    janvladimirmostert

    2 years ago
    a minor UI improvement would then be to hide the ones that are not applicable and only show JS or at least grey them out
    I'll take a look at klock, thanks! might not need a full-blown library for what i want to do
    s

    Sam

    2 years ago
    Depending on how simple your interactions with dates are (creation, simple compares, etc) you might be able to get away with some expect/actual with type aliases and some extension functions that delegate down to platform methods. It is what I do now, though my use cases are primarily for record keeping on models and some limited comparisons for sorting.
    j

    janvladimirmostert

    2 years ago
    i need to do some date comparisons and convert input strings to dates and calculate number of days, nothing hectic. expect/actual might be good enough, was hoping to avoid that though.
    Michal Harakal

    Michal Harakal

    2 years ago
    I have used with similar simple use case
    io.ktor.util.date.GMTDate
    from
    ktor-utils
    . A few extensions method for comparing and string conversions and you are done.
    j

    janvladimirmostert

    2 years ago
    awesome, thanks! will check out ktor utils as well
    Michal Harakal

    Michal Harakal

    2 years ago
    here project where I have used it … https://github.com/dukecon/dukecon_mobile
    Erik Christensen

    Erik Christensen

    2 years ago
    There's also Island Time, which is probably the most full-featured overall. But I'm also biased since I wrote it. 🙂 It doesn't support JS and every native platform yet though, which may or may not be an issue for you. https://github.com/erikc5000/island-time
    Rohen Giralt

    Rohen Giralt

    2 years ago
    I can’t vouch for any of the others, but I’ve been using Klock so far and it’s worked great. It uses inline classes, though, which gives the TimeSpan and DateTime classes less memory overhead. However, inline classes are still experimental, so they’re not supported in kotlinx.serialization yet and aren’t recommended for production.
    j

    janvladimirmostert

    2 years ago
    i'm using Kotlin 1.4 M2 in production as well as inline classes, and not planning to serialize the Klock values, so it should be fine. Klock is not supported in 1.4 M2 currently, apparently it will be in 1.4 or 1.4 RC, so waiting for that