Skip to content

Commit 6ee68b9

Browse files
committed
Fix errors when retrieving timezone from clock files.
1 parent 68fdf66 commit 6ee68b9

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
- Fixed the `weeks` property for negative `Period` instances.
88
- Fixed `start_of()` methods not setting microseconds to 0.
9+
- Fixed errors on some systems when retrieving timezone from clock files.
910

1011

1112
## [2.0.1] - 2018-05-10

pendulum/tz/local_timezone.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from typing import Union
1515

1616
from .timezone import Timezone, TimezoneFile
17+
from .zoneinfo.exceptions import InvalidTimezone
1718

1819

1920
_mock_local_timezone = None
@@ -200,16 +201,16 @@ def _get_unix_timezone(_root='/'): # type: (str) -> Timezone
200201
line = line[match.end():]
201202
etctz = line[:end_re.search(line).start()]
202203

203-
parts = etctz.replace(' ', '_').split('/')[-2:]
204+
parts = list(reversed(etctz.replace(' ', '_').split('/')))
205+
tzpath = []
204206
while parts:
205-
tzpath = '/'.join(parts)
207+
tzpath.insert(0, parts.pop(0))
208+
206209
try:
207-
return Timezone(tzpath)
208-
except (ValueError, IOError, OSError):
210+
return Timezone('/'.join(tzpath))
211+
except InvalidTimezone:
209212
pass
210213

211-
parts.pop(0)
212-
213214
# systemd distributions use symlinks that include the zone name,
214215
# see manpage of localtime(5) and timedatectl(1)
215216
tzpath = os.path.join(_root, 'etc/localtime')

0 commit comments

Comments
 (0)