-
Notifications
You must be signed in to change notification settings - Fork 533
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
Consider new helper methods for LocalResult
#716
Comments
Thanks for adding this @botahamec - and thanks @gerritsangel for the original comments - I think this is a great idea. As you mention this will be tricky without a breaking change, so its probably a pub struct LocalResult<T> {
naive_local: NaiveDateTime,
zoned: PotentiallyAmbiguous<T>,
}
enum PotentiallyAmbiguous<T> {
None,
Single(T),
Ambiguous(T, T),
} |
Why is this tricky without a breaking change? Why couldn't we add methods to today's definition of |
@djc I think we would need to modify the
|
@djc - because in the @botahamec - This is an interesting approach, we could leave |
@esheppa Interesting. I think we should try to do two methods though. One to find the next valid time, and one to find the previous valid time. I think to find we'd try to add an hour until we find a valid time, and then do a funky binary search to figure out the exact time we need. For most time zones, that should be fine because we're just worried about DST. But sometimes timezones will skip ahead by entire months, or someone will write a dummy time zone which always returns None (we'll also need to handle the case where the next valid time is ambiguous, for some reason). The binary search also doesn't work for a time zone where only the 10th and 30th seconds of each hour are valid. Maybe if the next hour doesn't work, we try the next day, then the next month, then the next year, then 100 years, then we do the maximum possible date time. That won't work for a time zone where the first second of every hour is skipped. The more I think about it, the harder it is for me to imagine that we could find a good default implementation. |
This is biting me too. I want to schedule something at time X in a given day. However it needs to be in the users time zone and I need to convert to UTC for the actual scheduling. It works fine in most cases when there is no ambiguity everything is simple, when the time occurs twice I just pick the first one (good enough for my use case). However right now if the "correct" time occurs during a jump I can't find any way to get the right time. For my purposes I would want to schedule at the jump, for example if the cock jumps from 01:59 -> 03:00 I want to run at 03:00. However I can't find any way to get this timestamp with chrono. Right now the best solution I have found is just adding a small amount of time to the date and keep trying until I get a result but this isn't great and doesn't give the best result. |
@kevincox For what it's worth, I think in that specific use case, you should probably create an error message saying that time doesn't exist on that day Now that I think about it, I'm not quite sure what I would consider to be a good use case for this API |
For my use case this is a repeating event and users would rather that it occurs on this day at the closest correct time instead of erroring out and missing a day. |
@kevincox Ah, that makes sense. I can imagine that causing problems too, but that's probably a fair compromise. |
Yeah, it isn't perfect for every use case but it works very well for my current problem. |
@kevincox - if you are using That being said, in |
Hi @kevincox - on a further review of the code I think my previous answer may be wrong. It looks like |
This is something I was just about to create an issue for. Lossy conversion is good enough for me, but there isn't really a way to do it at all now. |
I'm glad that this is considered a blocking issue for v0.5! This has caused some small trouble recently as daylight savings is approaching. To share some more thoughts and maybe spark some discussion: CasesForward Jumps
In summary I see the following information as being useful:
Backward Jumps
Single time
Current APIDatapub enum LocalResult<T> {
None,
Single(T),
Ambiguous(T, T),
} I think the obvious flaw here is that in the case of forward jumps we have no information. Something like Helper ModificationsTo integrate this new data into the helper set I took a look at what we have and what could be changed. Existing
|
|
From #687
I like what we have already (the
earliest
andlatest
methods might just be as far as we want to go), but I wanted to see what people think about this. I don't think there's anything we could do without a breaking change. One idea is to have the implementor of theTimeZone
interface provide a later or earlier time that would work.The text was updated successfully, but these errors were encountered: