Skip to content
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

Fix RecursionError when adding to a DateTime with a FixedTimezone #431

Merged
merged 1 commit into from
Jan 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion pendulum/tz/timezone.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,8 @@ def dst(self, dt): # type: Optional[datetime] # type: (...) -> timedelta
return timedelta()

def fromutc(self, dt): # type: (datetime) -> datetime
return (dt + self._utcoffset).replace(tzinfo=self)
# Use the stdlib datetime's add method to avoid infinite recursion
return (datetime.__add__(dt, self._utcoffset)).replace(tzinfo=self)

def tzname(self, dt): # type: Optional[datetime] # type: (...) -> Union[str, None]
return self._name
Expand Down
3 changes: 2 additions & 1 deletion tests/datetime/test_add.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,9 @@ def test_addition_invalid_type():
def test_add_to_fixed_timezones():
dt = pendulum.parse("2015-03-08T01:00:00-06:00")
dt = dt.add(weeks=1)
dt = dt.add(hours=1)

assert_datetime(dt, 2015, 3, 15, 1, 0, 0)
assert_datetime(dt, 2015, 3, 15, 2, 0, 0)
assert dt.timezone_name == "-06:00"
assert dt.offset == -6 * 3600

Expand Down