pytz icon indicating copy to clipboard operation
pytz copied to clipboard

Conversion to UTC wrong in pytz 2024.2

Open aquamatthias opened this issue 1 year ago • 2 comments

Hi,

I have this test code which started to fail with the latest release of pytz:

assert utc_str(datetime(2020, 1, 1, 0, 0, 0, 0, tzinfo=pytz.timezone("GMT"))) == "2020-01-01T00:00:00Z"

and fails with this error:

E       AssertionError: assert '2019-12-31T23:42:00Z' == '2019-12-31T23:00:00Z'

The utc_str function boils down to:

def utc_str(dt: datetime) -> str:
    return dt.astimezone(timezone.utc).strftime("%Y-%m-%dT%H:%M:%SZ")

It works as expected in pytz 2024.1. Am I doing something wrong?

Thanks for clarification!

aquamatthias avatar Oct 04 '24 07:10 aquamatthias

Is possibly related to issue #133

andy-maier avatar Jul 22 '25 15:07 andy-maier

If you think a timezone definition is incorrect, I probably can’t fix it. pytz is a direct translation of the Olson timezone database, and changes to the timezone definitions need to be made to this source. If you find errors they should be reported to the time zone mailing list, linked from http://www.iana.org/time-zones.

from https://pythonhosted.org/pytz/

Guess here is the wrong place to ask about a fix?

CarliJoy avatar Aug 01 '25 13:08 CarliJoy