Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion pendulum/tz/local_timezone.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
10 changes: 10 additions & 0 deletions tests/tz/test_local_timezone.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down