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 instance() behaviour with pytz offsets #158

Merged
merged 1 commit into from
Nov 8, 2017
Merged

Fix instance() behaviour with pytz offsets #158

merged 1 commit into from
Nov 8, 2017

Conversation

pR0Ps
Copy link
Contributor

@pR0Ps pR0Ps commented Nov 8, 2017

pytz has a class of timezone called a FixedOffset. This class only
stores an offset, not a zone name.

When calling instance() on a datetime that was using one of these
FixedOffset objects as a timezone, Pendulum would totally ignore the
offset and use the local timezone instead. This would happen even if a
tz argument was directly supplied to the instance() call.

Additionally, the fallback to a fixed offset would always use the
datetime's timezone, even it if was None and a tz argument was
supplied to the instance() call.

This commit makes 2 small changes:

  • The zone property of the "effective timezone" (the datetime's
    tzinfo with a fallback to the passed in tz) is only used if it is
    non-null. This fixes using FixedOffset objects as timezones.
  • The fallback to a fixed offset now uses the offset of the "effective
    timezone" instead of the datetime's offset. This correctly handles
    cases where the timezone on the datetime is None and a fallback is
    provided.

`pytz` has a class of timezone called a `FixedOffset`. This class only
stores an offset, not a zone name.

When calling `instance()` on a datetime that was using one of these
`FixedOffset` objects as a timezone, Pendulum would totally ignore the
offset and use the local timezone instead. This would happen even if a
`tz` argument was directly supplied to the `instance()` call.

Additionally, the fallback to a fixed offset would always use the
datetime's timezone, even it if was `None` and a `tz` argument was
supplied to the `instance()` call.

This commit makes 2 small changes:
- The `zone` property of the "effective timezone" (the datetime's
  `tzinfo` with a fallback to the passed in `tz`) is only used if it is
  non-null. This fixes using `FixedOffset` objects as timezones.
- The fallback to a fixed offset now uses the offset of the "effective
  timezone" instead of the datetime's offset. This correctly handles
  cases where the timezone on the datetime is `None` and a fallback is
  provided.
@sdispater sdispater merged commit a39d8ec into sdispater:master Nov 8, 2017
@sdispater
Copy link
Owner

Nice catch! Thanks a lot for this PR :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants