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
adding timedelta to datetime object is not timezone aware #67682
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee=Noneclosed_at=<Date2015-02-27.20:11:35.748>created_at=<Date2015-02-20.19:46:14.444>labels= ['type-bug', 'library']
title='adding timedelta to datetime object is not timezone aware'updated_at=<Date2015-03-02.23:53:20.458>user='https://bugs.python.org/gilsho'
I encountered a strange bug involving timezone aware datetime objects and timedelta objects.
The crux of the matter is that daylight savings time is considered a different timezone, and therefore the timezone of a datetime object is date dependent. However, adding a timedelta object to a datetime object seems to do the simple thing which is preserve the timezone object. The bug manifests itself whenever adding a timedelta object crosses a daylight savings time boundary.
The following code illustrates the problem. Note that the transition between PDT (Pacific daylight time) and PST (Pacific savings time) occurs on March 9th (ish)
Activity
gilsho commentedon Feb 20, 2015
I encountered a strange bug involving timezone aware datetime objects and timedelta objects.
The crux of the matter is that daylight savings time is considered a different timezone, and therefore the timezone of a datetime object is date dependent. However, adding a timedelta object to a datetime object seems to do the simple thing which is preserve the timezone object. The bug manifests itself whenever adding a timedelta object crosses a daylight savings time boundary.
The following code illustrates the problem. Note that the transition between PDT (Pacific daylight time) and PST (Pacific savings time) occurs on March 9th (ish)
bitdancer commentedon Feb 20, 2015
the tzinfo object is responsible for handling daylight savings time. This looks like a bug in pytz.
4kir4 commentedon Mar 2, 2015
pytz explicitly documents this case (crossing DST boundary). There is
tz.normalize() method.
Are any of tzinfo methods even called during
before + timedelta(days=2)?Also a DST transition is not the only reason the utc offset or tzname may
change.