-
Notifications
You must be signed in to change notification settings - Fork 103
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
Add unambiguous LocalDateTime.toInstant #461
Comments
Sure, we're open to adding this. Could you share the business logic you need this for? |
I have recurring events that happen during certain time windows, e.g. between 12:00 and 18:00, or 02:00 and 02:30, local time. My need is to compute the start and end of each of these windows as pairs of instants for a given set of days. The first example is straight forward, but the second example event happens twice or never certain days, and I need to be able to account for that. |
You've omitted the most interesting part: what are you planning to do to account for that? What's going to happen to the zero, one, or two |
My use cases are the following:
I hope this answers your question! As you say, there are many approaches that are ultimately equivalent. I think that my suggestion would be most ergonomic for my use case, but I could likely work with all the alternatives you proposed. |
Let's double-check my understanding using specific examples.
So, for an event like
If the answers are "yes, yes, no", then I believe you can implement that with today's API. |
Good examples, I think they highlight an issue with my proposed solution.
In this example, the event would not be skipped, but shortened to last for 15 minutes, between 02:15 and 02:30.
No, because there's a period of inactivity between two periods of activity. In this case, the event would be active between 02:00 and 02:15 before the shift, inactive between 01:16 and 02:00 after the shift, and active between 02:00 and 02:30 after the shift. The remaining time is 15 minutes at 02:00 before the shift, counting down to zero as the clock approaches 02:15.
No, again because of the gap between the occurrences. If the event was 02:00-04:00, then yes, the remaining would be 3 hours due the hour gained during the shift. Your examples made me realize that I need to know the instant when the shift in daylight savings time happens, not just translate certain |
It looks like the specific problem you want to solve is: find all |
Yes, I believe the problem can be stated this way. One approach I'm imagining is this:
|
As the documentation states, the function
LocalDateTime.toInstant(timeZone: TimeZone)
can be ambiguous.I would be greatly helped by a function that returns all the instants that correspond to the
LocalDateTime
in the specified time zone. For example something with the following signature:If there is no such instant, the resulting list would be empty.
Would you consider adding this to the library?
The text was updated successfully, but these errors were encountered: