File tree Expand file tree Collapse file tree 2 files changed +17
-0
lines changed
Expand file tree Collapse file tree 2 files changed +17
-0
lines changed Original file line number Diff line number Diff line change @@ -150,6 +150,9 @@ def _get_windows_timezone() -> Timezone:
150150
151151
152152def _get_darwin_timezone () -> Timezone :
153+ if tzenv := os .environ .get ("TZ" ):
154+ with contextlib .suppress (ValueError ):
155+ return _tz_from_env (tzenv )
153156 # link will be something like /usr/share/zoneinfo/America/Los_Angeles.
154157 link = os .readlink ("/etc/localtime" )
155158 tzname = link [link .rfind ("zoneinfo/" ) + 9 :]
Original file line number Diff line number Diff line change 77
88from pendulum .tz .local_timezone import _get_unix_timezone
99from pendulum .tz .local_timezone import _get_windows_timezone
10+ from pendulum .tz .local_timezone import get_local_timezone
11+ from pendulum .tz .timezone import Timezone
1012
1113
1214@pytest .mark .skipif (
@@ -50,3 +52,15 @@ def test_unix_etc_timezone_dir():
5052 tz = _get_unix_timezone (_root = root_path )
5153
5254 assert tz .name == "Europe/Paris"
55+
56+
57+ @pytest .mark .skipif (
58+ sys .platform == "win32" , reason = "Test only available for UNIX systems"
59+ )
60+ def test_unix_respects_TZ_env_var (monkeypatch ): # noqa: N802
61+ monkeypatch .setattr ("yourmodule._local_timezone" , None )
62+ monkeypatch .setenv ("TZ" , "Europe/Paris" )
63+
64+ tz = get_local_timezone ()
65+
66+ assert tz == Timezone ("Europe/Paris" )
You can’t perform that action at this time.
0 commit comments