-
Notifications
You must be signed in to change notification settings - Fork 110
Copy method #229
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
Comments
This suffers from the same problem that led us not to provide We did get a request that may be similar though: #225, as well as several others. To design a good solution that is also safe, we are still collecting the use cases. Could you please describe yours? |
For my app, Seconds and nanoseconds are unimportant when comparing two localtime.
|
So, this is exactly the same request as #225—you just want truncation—just with an additional use case of comparing the two values. Could you clarify the use case though? Why is it that |
I create 21 tasks to quit smoking. Each task has a time slot in it. For example, in the first task, I expect him to smoke at certain time intervals. I use time comparison to color the cards.
|
Wouldn't the whole approach be buggy when DST transitions happen? For example, if the clocks are moved from 15:00 to 16:00 immediately, then having a colored card for the hour between 15:00 and 16:00 would be meaningless on that day. |
You're right. However, this project has not been completed yet. Also, clocks are not forwarded or backwards in my country. So if I publish the app in my country, it won't be a problem. But as I said, this project has not been completed yet and it is unclear in which countries it will be published. I don't quite understand why DST transitions cause problems in the copy method. In my case I am able to accept the copy method oblivious to time zones. |
Can you be sure that a month from now your government doesn't decide that your country should move clocks forward and backward?
They cause problems because the copy method takes an existing This is not a theoretical concern: we checked how people use |
I can understand your concern here. Created before DST |
In case you need such functionality, you can create an ext function yourself: fun LocalDateTime.copy(
year: Int? = null,
monthNumber: Int? = null,
dayOfMonth: Int? = null,
hour: Int? = null,
minute: Int? = null,
second: Int? = null,
) = LocalDateTime(
year ?: this.year,
monthNumber ?: this.monthNumber,
dayOfMonth ?: this.dayOfMonth,
hour ?: this.hour,
minute ?: this.minute,
second ?: this.second,
) then you can use it like this: val dateTime = LocalDateTime(2024, 5, 8, 18, 25, 30)
dateTime.copy(hour=21) // equivalent to LocalDateTime(2024, 5, 8, 21, 25, 30)
dateTime.copy(year=2048) // equivalent to LocalDateTime(2048, 5, 8, 18, 25, 30) |
Hi, Sometimes, I need copy method like data class copy. I couldn't find any copy method. So, I created a new method for copy. But, I would expect this to be in the standard library.
I'm curious about your thoughts on this subject.
The text was updated successfully, but these errors were encountered: