Thread
#stdlib
    r

    rrva

    2 years ago
    Give me an elegant way to express “Is T1 more than 15 minutes ago” in Kotlin. Is anything happening at https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.time/ ? I am using ChronoUnit.MINUTES.between now, but thinking is there is something even more readable
    You can mark @ T1 and then check
    mark.elapsedNow >= 15.minutes
    r

    rrva

    2 years ago
    thanks
    and this is experimental in what way? like, slated for un-experimentalness soon?
    gsala

    gsala

    2 years ago
    /**
     * This annotation marks the experimental preview of the standard library API for measuring time and working with durations.
     *
     * > Note that this API is in a preview state and has a very high chance of being changed in the future.
     * Do not use it if you develop a library since your library will become binary incompatible
     * with the future versions of the standard library.
     *
     * Any usage of a declaration annotated with `@ExperimentalTime` must be accepted either by
     * annotating that usage with the [OptIn] annotation, e.g. `@OptIn(ExperimentalTime::class)`,
     * or by using the compiler argument `-Xopt-in=kotlin.time.ExperimentalTime`.
     */
    In addition, classes like
    Duration
    are based on
    inline classes
    which are experimental themselves.
    Zach Klippenstein (he/him) [MOD]

    Zach Klippenstein (he/him) [MOD]

    2 years ago
    Generally, experimental APIs are fine to use in app code as long as you're willing to accept the risk of potentially having to update call sites when you update your kotlin version in the future. They're not safe for libraries since they might break binary compatibility.
    r

    rrva

    2 years ago
    This is application code which can undergo migration when upgrading to another kotlin version so not a biggie, still I am pondering if depending on Optin experimental timemark is easier than depending on https://github.com/markov/lucid-time when it comes to the upgrade effort
    but probably timemark is still the way to go
    eh, lucid-time did not even solve all of what I wanted to express, forget about that
    hmm how to convert an OffsetDateTime to a TimeMark