Skip to content

Commit

Permalink
Fix tz.gettz() not returning local time for empty string
Browse files Browse the repository at this point in the history
nocache checks the gettz(name) parameter with if not name and tries to get the local time from the TZ environment variable. When the environment variable does not exist, it only checked for name is None, skipping the logic that searches for the local time tzfile when passed an empty string.

Fixes #925, #926
  • Loading branch information
ffe4 committed Apr 3, 2020
1 parent 16e9c62 commit 96358e6
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
2 changes: 2 additions & 0 deletions changelog.d/1024.misc.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fixed tz.gettz() not returning local time when passed an empty string.
Reported by @labrys (gh issues #925, #926). Fixed by @ffe4 (gh pr #1024)
6 changes: 6 additions & 0 deletions dateutil/test/test_tz.py
Original file line number Diff line number Diff line change
Expand Up @@ -1077,6 +1077,12 @@ def testGettzCacheTzLocal(self):
local2 = tz.gettz()

assert local1 is not local2

def test_gettz_same_result_for_none_and_empty_string(self):
local1 = tz.gettz()
local2 = tz.gettz("")

assert local1 == local2


@pytest.mark.gettz
Expand Down
2 changes: 1 addition & 1 deletion dateutil/tz/tz.py
Original file line number Diff line number Diff line change
Expand Up @@ -1596,7 +1596,7 @@ def nocache(name=None):
name = os.environ["TZ"]
except KeyError:
pass
if name is None or name == ":":
if not name or name == ":":
for filepath in TZFILES:
if not os.path.isabs(filepath):
filename = filepath
Expand Down

0 comments on commit 96358e6

Please sign in to comment.