-
Notifications
You must be signed in to change notification settings - Fork 15
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
Unexpected behavior of disambiguate during dst change foreward #150
Comments
Happy to explain. This probably warrants a note in the docs. The reasons for this behavior:
The figure in the Python docs here also shows how this ‘extrapolation’ makes sense graphically. edit: |
Thank you for the insight. What do you think is the best way to find the time after the DST switch? def find_time_after_dst_switch(dt: SystemDateTime, time: Time) -> Instant:
# DST changes typically occur on the full minute
time = time.replace(second=0, nanosecond=0)
hour = time.hour
minute = time.minute
while True:
minute += 1
if minute >= 60:
minute = 0
hour += 1
if hour >= 24:
hour = 0
time = time.replace(hour=hour, minute=minute)
try:
return dt.replace_time(time.replace(hour=hour, minute=minute), disambiguate='raise').instant()
except SkippedTime:
continue |
@spacemanspiff2007 there's no clean way to do this, I'm afraid. This information would need to be exposed by Some potential improvements to your code:
Here is a naive algorithm which can be improved by bisect, and probably has some bugs in it still... skipped_time = SystemDateTime(...)
guess = skipped_time.local().subtract(hours=48, ignore_dst=True) # assume there are no two transitions so closeby
while True:
try:
guess.add(minutes=1, ignore_dst=True).assume_system_tz(disambiguate="raise")
except SkippedTime:
break |
@spacemanspiff2007 I've added an explicit note to the docs in the section about ambiguity. Let me know if you have any other ideas/suggestions. |
When the dst change means that the clock moves forward disambiguate behaves rather unexpected.
I would have expected that
earlier
returns the time before the switch forward andlater
returns the time when the switch is complete.However
whenever
is guessing that I might want to add/subtract an hour and does that for me resulting in the following behavior (Which is in brief described here)What I would have expected
Could you explain the reasoning behind this behavior?
The text was updated successfully, but these errors were encountered: