You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
DayLocator is returning incorrect times around daylights switch over #9018
I'm not sure why it just works for dateutil and not for pytz, but I think the issue is that by passing tz to the DayLocator, you're telling the DayLocator that your points should represent that absolute time (it's possible it's represented internally as UTC), and by passing tz again to the formatter, you're converting that back, and that's where the error lies. If you want to keep with the pytz zones, this version of the code will also work as expected:
OK, I found the problem, I can prepare a patch for this. The issue is that the rrule is being constructed using timezone-aware dates. This is problematic even for dateutil zones, for various reasons, but it's especially problematic for pytz zones, which do not implement the tzinfo interface in the recommended fashion.
What needs to happen is that RRuleLocator needs to generate naive dates, which, in the case of pytz zones, are then localized (I think it doesn't matter which side of DST they end up on in ambiguous situations, but I think we should default to the DST side for PEP-495 related reasons), and for dateutil zones, they can just be attached as normal.
One thing to note (and I will make a separate issue to discuss this if my suspicions prove correct) is that I am fairly certain that the current approach will have this same bug if there's ever a DST transition that starts at midnight (i.e. if midnight doesn't exist in a given zone) - though it may be less obvious.
Activity
pganssle commentedon Aug 12, 2017
FWIW, this is specifically an issue with
pytztime zones:pganssle commentedon Aug 13, 2017
I'm not sure why it just works for
dateutiland not forpytz, but I think the issue is that by passingtzto theDayLocator, you're telling theDayLocatorthat your points should represent that absolute time (it's possible it's represented internally as UTC), and by passingtzagain to the formatter, you're converting that back, and that's where the error lies. If you want to keep with thepytzzones, this version of the code will also work as expected:pganssle commentedon Aug 13, 2017
OK, I found the problem, I can prepare a patch for this. The issue is that the
rruleis being constructed using timezone-aware dates. This is problematic even fordateutilzones, for various reasons, but it's especially problematic forpytzzones, which do not implement thetzinfointerface in the recommended fashion.What needs to happen is that
RRuleLocatorneeds to generate naive dates, which, in the case ofpytzzones, are thenlocalized(I think it doesn't matter which side of DST they end up on in ambiguous situations, but I think we should default to the DST side for PEP-495 related reasons), and fordateutilzones, they can just be attached as normal.One thing to note (and I will make a separate issue to discuss this if my suspicions prove correct) is that I am fairly certain that the current approach will have this same bug if there's ever a DST transition that starts at midnight (i.e. if midnight doesn't exist in a given zone) - though it may be less obvious.
LanceJenkinZA commentedon Aug 17, 2017
Thanks for looking into the problem, and creating a patch fixing it!