Skip to content

Wrong timezone name when using zoneinfo #812

Description

@jaap3

Overview Description

While running a project's test suite using Django 4.0a1 I noticed a failing test related to time formatting. After some debugging I've boiled down the root cause to Django's switch from pytz to zoneinfo and python-babel's format_time function giving the wrong result.

Steps to Reproduce

import datetime
import zoneinfo
from babel.dates import format_time

tz = zoneinfo.ZoneInfo('Europe/Amsterdam')
start = datetime.datetime(2020, 11, 12, 10, 15, tzinfo=tz)
format_time(start, 'z', locale='nl')

Actual Results

'CEST'

Expected Results

'CET'

Reproducibility

Using strftime (i.e. start.strftime('%Z')) the result is as epected.
Using pytz (i.e. tz = pytz.timezone('Europe/Amsterdam'); start = tz.localize(...)) the result is also as expected.

Activity

  1. jaap3 commented on Feb 16, 2023

    @jaap3
    Author

    Seems like we were doing it wrong (but it worked), using format_datetime does give the correct result. Using format_time doesn't take the date into account, so the result was always CET.

    I also had the actual and expected results in the wrong order, sorry for the noise ☺️.

  2. akx commented on Feb 16, 2023

    @akx
    Member

    @jaap3 Glad you got it sorted out! For the record, Babel 2.12 (not released yet) will prefer zoneinfo to pytz: #940

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions