Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Instant support Chrono fields #437

Closed
chrisjenx opened this issue Sep 22, 2024 · 4 comments
Closed

Instant support Chrono fields #437

chrisjenx opened this issue Sep 22, 2024 · 4 comments

Comments

@chrisjenx
Copy link

Most other date packages support setting the fields of each time unit on something like ZonedDateTime DateTime etc

Would be nice if we could do System.now().withHour(0).withMinute(0).withSecond(0).withNano(0) etc

Mostly for flexibility in the API, but there is cases where we don't want/need nanosecond precision, API calls, DB storage etc.

@dkhalanskyjb
Copy link
Collaborator

Duplicate of #325, please share your use cases in detail there. In particular, it seems at the moment that the needs for adjusting the precision for API calls and DB storage is already covered by rounding not at the moment of constructing the Instant but at the moment of serializing it to a string: https://kotlinlang.org/api/kotlinx-datetime/kotlinx-datetime/kotlinx.datetime.format/-date-time-format-builder/-with-time/second-fraction.html If not, please share what exactly you are trying to do that's inconvenient with our library currently.

@dkhalanskyjb dkhalanskyjb closed this as not planned Won't fix, can't repro, duplicate, stale Sep 23, 2024
@chrisjenx
Copy link
Author

We use Exposed. Guess I could create a new db column but there's loads of places we use it. After parsing API requests from. Third party clients. It's pretty common.

@chrisjenx
Copy link
Author

Also turning it to a string to remove milliseconds then back to an instant, is pretty poor performance wise.

@dkhalanskyjb
Copy link
Collaborator

We use Exposed.

I haven't used Exposed, so this doesn't tell me much, sorry.

After parsing API requests from. Third party clients. It's pretty common.

If I understood you correctly, third-party clients send you something like 2024-09-23T17:32:20.123456789, and you want to lower the precision and keep something like 2024-09-23T17:32:20.123, right? But why? What's the problem with keeping the whole 2024-09-23T17:32:20.123456789?

If you can give some examples of the code that is inconvenient to write and explain its purpose, it will help a lot. Pseudocode is also fine.

Also turning it to a string to remove milliseconds then back to an instant, is pretty poor performance wise.

That's not what I was suggesting. I meant that if you need to send a string somewhere anyway, you may as well lower the precision in the string itself, without rounding the Instant. If you want to receive an Instant, this approach won't work, yes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants