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

janvladimirmostert

06/22/2020, 11:48 AM
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

06/22/2020, 11:52 AM
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
👍 1
j

janvladimirmostert

06/22/2020, 12:03 PM
that's what i thought, strange that it's labelled Common, JS, JVM, Native when it's on a kotlin.js page
t

Tijl

06/22/2020, 12:04 PM
it’s labeled js
in my browser at least
j

janvladimirmostert

06/22/2020, 12:05 PM
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
👍 2
t

Tijl

06/22/2020, 12:05 PM
we use Klock for some things at my company (not me personally), didn’t hear any complaints
j

janvladimirmostert

06/22/2020, 12:06 PM
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
👍 1
I'll take a look at klock, thanks! might not need a full-blown library for what i want to do
s

Sam

06/22/2020, 3:40 PM
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

06/22/2020, 3:43 PM
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.
m

Michal Harakal

06/22/2020, 3:58 PM
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

06/22/2020, 3:59 PM
awesome, thanks! will check out ktor utils as well
m

Michal Harakal

06/22/2020, 4:00 PM
here project where I have used it … https://github.com/dukecon/dukecon_mobile
e

Erik Christensen

06/22/2020, 11:20 PM
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
👍 1
r

Rohen Giralt

06/26/2020, 12:19 PM
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

06/26/2020, 12:59 PM
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
👍 1
2 Views