Remove `dt` argument from `ZoneInfo.tzname`

I’d like to suggest removing the dt argument from ZoneInfo.tzname. Maybe I’m missing something, but given that the object itself is already a timezone information I don’t think that a datetime object is necessary for retrieving the tzname.

from datetime import datetime
from zoneinfo import ZoneInfo
>>> LOS_ANGELES = ZoneInfo("America/Los_Angeles")
>>> # Current implementation
>>> LOS_ANGELES.tzinfo(datetime.now())
'PDT'
>>> # Suggestion
>>> LOS_ANGELES.tzinfo()
'PDT'

Also, there’s a couple of other methods that I don’t think needs to receive datetime and maybe are candidates for removing as well:

  • ZoneInfo.dst
  • ZoneInfo.utcoffset
>>> LOS_ANGELES.tzinfo(datetime.now())
'PDT'
>>> # Suggestion
>>> LOS_ANGELES.tzinfo()
'PDT'

Isn’t the current (or otherwise relevant) time necessary so that it can say PDT and not PST?

1 Like

Yes, dt parameter of these 3 methods is necessary because all their return values can depend on the date (if DST is currently applied or not).

I see, I don’t have experience with daylight savings, it makes sense.

But also, many time zones don’t have difference between Standard Time and Daylight Saving Time. In such cases, It feels very odd to create a datetime object just for getting the tzname.

Anyway, thank you guys for clarifying this

It’s not obvious from the signature[1], but you can pass None and I think the inner function will do the right thing.


  1. perhaps it should be a default? ↩︎

1 Like

For completeness, here is an example of different timezone name depending on the date:

$ python
>>> import datetime, zoneinfo
>>> paris = zoneinfo.ZoneInfo("Europe/Paris")
>>> paris.tzname(datetime.datetime(2024, 1, 1)) # winter
'CET'
>>> paris.tzname(datetime.datetime(2024, 7, 1)) # summer
'CEST'
1 Like