Does anyone know why klock backs its datetimes wit...
# announcements
n
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
Most likely for JS compatibilty, because JS has no native 64 bit int
p
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
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
Yeah, I don’t think it’s de facto either.
3
n
IMHO if you really need to deal with that, I would back it generically
p
I think it’s just the only option for MPP other than rolling your own dates.
n
MPP means kotlin native?
d
And JS
n
multi-platform, not necessarily native
👆 3
p
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
I rolled my own, but I wouldn't recommend it.
It gets hairy when you get to parsing and formatting
p
date/time is not a fun problem in general 😬
d
If you only need the JVM I can recommend just sticking with java.time, it works great
n
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
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
I looked for the IANA DB in Klock, but didn’t see it. Did I miss it?
n
@pardom what do you mean, solely the date implementation? what is klock if not that?
n
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
@Nir what I meant by that was a way to retrieve time.
I was unclear about that.
n
just a timestamp or do you need to format it?
n
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
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
@gildor this is fine on the JVM but e.g. for native, using the C stuff is a disaster.
g
yes, there is no perfect solution indeed
n
couldn't you use any C library you wanted on the C backend?
n
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
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
@karelpeeters thanks for linking, I wrote a pretty long reply on the thread
k
You should write that reply on the issue 😛
n
Yeah, definitely not a fan of the double thing
I did
Check it out 🙂