summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Lemm <61800298+ffe4@users.noreply.github.com>2020-04-24 09:43:38 -0400
committerPaul Ganssle <paul@ganssle.io>2020-04-24 13:32:16 -0400
commitbd69e8e964b6572184ab6bf49b651fba617eae4f (patch)
tree330313411dd8336059de38c64152fc700d0bf6fa
parent4a50ff7c8ead9cb4c02080d9f8f302e2ea7b34bd (diff)
downloaddateutil-git-bd69e8e964b6572184ab6bf49b651fba617eae4f.tar.gz
Fix tz.gettz() behavior with empty string
The documented behavior of the function is to return a local time zone when the argument is None or an empty string. This was working if the TZ environment variable was set, but not working otherwise. Fixes #925, #926
-rw-r--r--changelog.d/1024.misc.rst2
-rw-r--r--dateutil/test/test_tz.py9
-rw-r--r--dateutil/tz/tz.py2
3 files changed, 12 insertions, 1 deletions
diff --git a/changelog.d/1024.misc.rst b/changelog.d/1024.misc.rst
new file mode 100644
index 0000000..d55f738
--- /dev/null
+++ b/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) \ No newline at end of file
diff --git a/dateutil/test/test_tz.py b/dateutil/test/test_tz.py
index 6cd8ea0..e5e4772 100644
--- a/dateutil/test/test_tz.py
+++ b/dateutil/test/test_tz.py
@@ -1080,6 +1080,15 @@ class GettzTest(unittest.TestCase, TzFoldMixin):
@pytest.mark.gettz
+def test_gettz_same_result_for_none_and_empty_string():
+ local_from_none = tz.gettz()
+ local_from_empty_string = tz.gettz("")
+ assert local_from_none is not None
+ assert local_from_empty_string is not None
+ assert local_from_none == local_from_empty_string
+
+
+@pytest.mark.gettz
@pytest.mark.parametrize('badzone', [
'Fake.Region/Abcdefghijklmnop', # Violates several tz project name rules
])
diff --git a/dateutil/tz/tz.py b/dateutil/tz/tz.py
index af81e88..320708d 100644
--- a/dateutil/tz/tz.py
+++ b/dateutil/tz/tz.py
@@ -1596,7 +1596,7 @@ def __get_gettz():
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