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

If you have the /etc/timezone file set to a timezone string, pendulum.UTC has that timezone's utcoffset instead of None #814

Open
2 tasks done
gibsondan opened this issue Mar 12, 2024 · 1 comment

Comments

@gibsondan
Copy link

gibsondan commented Mar 12, 2024

  • I am on the latest Pendulum version.
  • I have searched the issues of this repo and believe that this is not a duplicate.
  • OS version and name: linux docker container (python3.10-slim) running on a mac
  • Pendulum version: 3.0.0

Issue

This appears to be a bug in ZoneInfo that moved into pendulum in the 3.0 release now that TimeZone subclasses ZoneInfo.

Simple repro:

In a Docker container:

FROM python:3.10-slim

RUN pip install pendulum

RUN echo "Asia/Shanghai" > /etc/timezone

Then in Python:

import pendulum, datetime
pendulum.UTC.utcoffset(datetime.datetime(2024, 3, 12, 0, 0, 0, 0)))

outputs datetime.timedelta(seconds=28800) (the utcoffset of the timezone in /etc/timezone) instead of the expected None return value for UTC.

This breaks all kinds of things.

The same issue happens with a ZoneInfo object:

datetime.timedelta(seconds=28800)

See https://stackoverflow.com/questions/74467999/why-does-zoneinfoutc-do-different-time-conversions-from-timezone-utc for a similar report on ZoneInfo.

@gibsondan gibsondan changed the title If you have the /etc/timezone file set to a timezone, pendulum.UTC has that timezone's utcoffset instead of None If you have the /etc/timezone file set to a timezone string, pendulum.UTC has that timezone's utcoffset instead of None Mar 12, 2024
@gibsondan
Copy link
Author

Filed this in cpython too since it seems the bug here is really in ZoneInfo not pendulum: python/cpython#116676

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

No branches or pull requests

1 participant