https://kotlinlang.org logo
Title
n

Nir

07/09/2019, 2:32 PM
Does anyone know why klock backs its datetimes with double instead of integer? This is... Very odd. Is klock the standard for datetime stuff in kotlin?
d

diesieben07

07/09/2019, 2:33 PM
Most likely for JS compatibilty, because JS has no native 64 bit int
p

pardom

07/09/2019, 2:36 PM
Is klock the standard for datetime stuff in kotlin?
I don’t think there is a standard at this point. It would be nice if mpp dates were in the stdlib.
n

Nir

07/09/2019, 2:38 PM
I didn't mean "standard" like in the standard library, more like "de facto standard" 🙂
@diesieben07 That's a very logical reason, but yikes!
p

pardom

07/09/2019, 2:39 PM
Yeah, I don’t think it’s de facto either.
3
n

Nir

07/09/2019, 2:39 PM
IMHO if you really need to deal with that, I would back it generically
p

pardom

07/09/2019, 2:39 PM
I think it’s just the only option for MPP other than rolling your own dates.
n

Nir

07/09/2019, 2:39 PM
MPP means kotlin native?
d

diesieben07

07/09/2019, 2:39 PM
And JS
n

Nicholas Bilyk

07/09/2019, 2:39 PM
multi-platform, not necessarily native
👆 3
p

pardom

07/09/2019, 2:39 PM
There’s a lot in klock that I don’t necessarily want to import.
I think there ought to be a project solely focused on the date implementation. Similar to this project solely focused on UUID https://github.com/benasher44/uuid
👍 1
n

Nicholas Bilyk

07/09/2019, 2:42 PM
I rolled my own, but I wouldn't recommend it.
It gets hairy when you get to parsing and formatting
p

pardom

07/09/2019, 2:43 PM
date/time is not a fun problem in general 😬
d

diesieben07

07/09/2019, 2:44 PM
If you only need the JVM I can recommend just sticking with java.time, it works great
n

Nicholas Bilyk

07/09/2019, 2:46 PM
you can create expect/actual methods for things like parsing and then defer to the platform's defacto implementation like js Intl package and jvm calendar stuff. It works well but you get implementation differences
n

Nir

07/09/2019, 2:47 PM
Rolling your own just isn't realistic tbh
unless you only need very basic stuff
if you need to actually do timezone stuff for example it's a non-starter
👆 1
writing a parser for the IANA database, etc
p

pardom

07/09/2019, 2:48 PM
I looked for the IANA DB in Klock, but didn’t see it. Did I miss it?
n

Nir

07/09/2019, 2:48 PM
@pardom what do you mean, solely the date implementation? what is klock if not that?
n

Nicholas Bilyk

07/09/2019, 2:48 PM
by 'rolling my own' I meant just writing apis that give you a common way to access the different backends
and then the backends have the normal way they do time
p

pardom

07/09/2019, 2:49 PM
@Nir what I meant by that was a way to retrieve time.
I was unclear about that.
n

Nicholas Bilyk

07/09/2019, 2:49 PM
just a timestamp or do you need to format it?
n

Nir

07/09/2019, 2:49 PM
What is the "de facto" implementation on native?
The C stuff is not good to say the least.
@pardom Having seen multiple implementations that went badly wrong, I'd have to say I disagree. time, dates, timezones, all needs to be planned as one library.
It's very hard to retrofit things later, design wise.
These things are intimately connected, so logically you are going to arrive at a better overall design if you take it all into consideration at once
I think you are right, I don't think klock actually has TZ support 😞
As for 1.0 Klock doesn’t have direct TimeZone support. But support offseted DateTime using DateTimeTz.
So, both python datetime and C++ boost datetime started with approaches like this... and both are a total mess to use once you need "real" timezone support.
g

gildor

07/09/2019, 3:10 PM
klock is not a standard and not even “de facto” standard, is just a community library, there are plans for full-blown date/time library for MPP, but it doesn’t exist yet, for now just better to use platform specific API with own MPP wrapper
n

Nir

07/09/2019, 3:13 PM
@gildor this is fine on the JVM but e.g. for native, using the C stuff is a disaster.
g

gildor

07/09/2019, 3:14 PM
yes, there is no perfect solution indeed
n

Nicholas Bilyk

07/09/2019, 3:14 PM
couldn't you use any C library you wanted on the C backend?
n

Nir

07/09/2019, 3:19 PM
I'm just not aware of any really good C library solution for this.
You could probably find something that would be correct, but the API, type correctness, etc, of the library, would be very poor (because it's C)
It would be a massive step down from e.g. C++ date, or the java libraries
k

karelpeeters

07/09/2019, 9:06 PM
I think one of the JB guys posted a preliminary date/time API design to ask feedback on about a month ago, but I can't seem to find it. Does anyone have the link?
So, what I wanted to say: look like the plan for the Kotlin stdlib is to store it as a double as well: https://github.com/Kotlin/KEEP/blob/durations/proposals/stdlib/durations-and-clocks.md#duration
n

Nir

07/09/2019, 9:55 PM
@karelpeeters thanks for linking, I wrote a pretty long reply on the thread
k

karelpeeters

07/09/2019, 9:55 PM
You should write that reply on the issue 😛
n

Nir

07/09/2019, 9:55 PM
Yeah, definitely not a fan of the double thing
I did
Check it out 🙂