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
Fixes #925, #926
  • Loading branch information
ffe4 committed Apr 3, 2020
1 parent 16e9c62 commit 841cc6c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
2 changes: 2 additions & 0 deletions changelog.d/1024.misc.rst
@@ -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)
11 changes: 11 additions & 0 deletions dateutil/test/test_tz.py
Expand Up @@ -1077,6 +1077,17 @@ 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.skipif(IS_WIN, reason='requires Unix')
def test_gettz_returns_local_time(self):
with TZEnvContext('/etc/localtime'):
assert tz.gettz() == tz.tzfile('/etc/localtime')


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

0 comments on commit 841cc6c

Please sign in to comment.