Fix instance() behaviour with pytz offsets #158
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
pytz
has a class of timezone called aFixedOffset
. This class onlystores an offset, not a zone name.
When calling
instance()
on a datetime that was using one of theseFixedOffset
objects as a timezone, Pendulum would totally ignore theoffset and use the local timezone instead. This would happen even if a
tz
argument was directly supplied to theinstance()
call.Additionally, the fallback to a fixed offset would always use the
datetime's timezone, even it if was
None
and atz
argument wassupplied to the
instance()
call.This commit makes 2 small changes:
zone
property of the "effective timezone" (the datetime'stzinfo
with a fallback to the passed intz
) is only used if it isnon-null. This fixes using
FixedOffset
objects as timezones.timezone" instead of the datetime's offset. This correctly handles
cases where the timezone on the datetime is
None
and a fallback isprovided.