From 3b14ec89d219befb1bf8749443c6338df7984888 Mon Sep 17 00:00:00 2001 From: EEB Date: Fri, 1 May 2020 17:36:21 +0000 Subject: [PATCH 1/2] adding new test for unix that we can set env var and it is highest priority local timezone --- tests/tz/test_local_timezone.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/tz/test_local_timezone.py b/tests/tz/test_local_timezone.py index fdf1cc2f..478f4a36 100644 --- a/tests/tz/test_local_timezone.py +++ b/tests/tz/test_local_timezone.py @@ -7,6 +7,16 @@ from pendulum.tz.local_timezone import _get_windows_timezone +@pytest.mark.skipif( + sys.platform == "win32", reason="Test only available for UNIX systems" +) +def test_unix_environment_variable(monkeypatch): + # localtime can be set on unix with TZ environment variable + monkeypatch.setenv("TZ", "UTC") + tz = _get_unix_timezone() + assert tz.name == "UTC" + + @pytest.mark.skipif( sys.platform == "win32", reason="Test only available for UNIX systems" ) From e3a96c92f9a41ff7ad0f7eaa8ca1d42511051ab1 Mon Sep 17 00:00:00 2001 From: EEB Date: Fri, 1 May 2020 17:38:30 +0000 Subject: [PATCH 2/2] fixing local timezone setting edge case on unix - if a directory named the same as the timezone exists, attempts to read it as a file even if it is not a timezone file --- pendulum/tz/local_timezone.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pendulum/tz/local_timezone.py b/pendulum/tz/local_timezone.py index 08a6e4fa..09747aee 100644 --- a/pendulum/tz/local_timezone.py +++ b/pendulum/tz/local_timezone.py @@ -248,7 +248,11 @@ def _tz_from_env(tzenv): # type: (str) -> Timezone # TZ specifies a file if os.path.exists(tzenv): - return TimezoneFile(tzenv) + try: + return TimezoneFile(tzenv) + except FileNotFoundError: + # if cannot load from timezone file, assume path existing is coincidence + pass # TZ specifies a zoneinfo zone. try: