regebro / tzlocal

A Python module that tries to figure out what your local timezone is
MIT License
185 stars 58 forks source link

get_localzone_name() don't check if returned TZ is valid #150

Closed When-No-Light closed 11 months ago

When-No-Light commented 1 year ago

In my tests I use pyfakefs.fake_filesystem_unittest to mock system files, and I found that in case when I have mocked "/etc/timezone" and real "/usr/share/zoneinfo" files, function get_localzone() return string from "/etc/timezone". It could be invalid TZ, something like "Incorrect/TZ" or "123". But when you use reload_localzone() it raises ZoneInfoNotFoundError exception, get_localzone() return object that don't has "key" attr.

I had this problem on Ubuntu 23.04 and tzlocal==5.0.1

regebro commented 12 months ago

get_localzone() returns a timezone object, so the name in the file has to be valid, or it can't return.

ZoneInfoNotFoundError is the correct and expected behavior when you have configured a timezone that isn't valid.