Skip to content

Commit e53b959

Browse files
committed
Merge branch 'master' into develop
2 parents 8af1c06 + 4213d76 commit e53b959

File tree

13 files changed

+72
-14
lines changed

13 files changed

+72
-14
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
### 0.5.5
2+
3+
(September 1st, 2016)
4+
5+
- [Fix] Fixes local timezone loading for unix systems.
6+
- [Fix] Fixes potential `AttributeError` in `between` method. (Thanks to [iv597](https://github.com/iv597))
7+
18
### 0.5.4
29

310
(August 30th, 2016)

docs/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
# The short X.Y version.
6161
version = '0.5'
6262
# The full version, including alpha/beta/rc tags.
63-
release = '0.5.4'
63+
release = '0.5.5'
6464

6565
# The language for content autogenerated by Sphinx. Refer to documentation
6666
# for a list of supported languages.

pendulum/pendulum.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1113,9 +1113,6 @@ def between(self, dt1, dt2, equal=True):
11131113
11141114
:rtype: bool
11151115
"""
1116-
dt1 = self._get_datetime(dt1)
1117-
dt2 = self._get_datetime(dt2)
1118-
11191116
if dt1 > dt2:
11201117
dt1, dt2 = dt2, dt1
11211118

pendulum/tz/loader.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,14 @@ def load(cls, name):
3838
except _compat.FileNotFoundError:
3939
raise ValueError('Unknown timezone [{}]'.format(name))
4040

41+
@classmethod
42+
def load_from_file(cls, filepath):
43+
try:
44+
with open(filepath, 'rb') as f:
45+
return cls._load(f)
46+
except _compat.FileNotFoundError:
47+
raise ValueError('Unable to load file [{}]'.format(filepath))
48+
4149
@classmethod
4250
def _load(cls, fp):
4351
head_fmt = '>4s c 15x 6l'

pendulum/tz/local_timezone.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -86,16 +86,14 @@ def get_tz_name_for_windows(cls):
8686
return get_localzone_name()
8787

8888
@classmethod
89-
def get_tz_name_for_unix(cls):
89+
def get_tz_name_for_unix(cls, _root='/'):
9090
tzenv = os.environ.get('TZ')
9191
if tzenv:
9292
try:
9393
return _tz_from_env(tzenv)
9494
except ValueError:
9595
pass
9696

97-
_root = '/'
98-
9997
# Now look for distribution specific configuration files
10098
# that contain the timezone name.
10199
tzpath = os.path.join(_root, 'etc/timezone')
@@ -150,22 +148,23 @@ def get_tz_name_for_unix(cls):
150148
tzpath = os.path.join(_root, 'etc/localtime')
151149
if os.path.exists(tzpath) and os.path.islink(tzpath):
152150
tzpath = os.path.realpath(tzpath)
153-
start = tzpath.find("/") + 1
154-
while start is not 0:
155-
tzpath = tzpath[start:]
151+
parts = tzpath.split('/')[-2:]
152+
while parts:
153+
tzpath = '/'.join(parts)
156154
try:
157155
return Timezone.load(tzpath)
158-
except ValueError:
156+
except (ValueError, IOError, OSError):
159157
pass
160-
start = tzpath.find("/") + 1
158+
159+
parts.pop(0)
161160

162161
# No explicit setting existed. Use localtime
163162
for filename in ('etc/localtime', 'usr/local/etc/localtime'):
164163
tzpath = os.path.join(_root, filename)
165164

166165
if not os.path.exists(tzpath):
167166
continue
168-
return Timezone('', *Loader.load(tzpath))
167+
return Timezone('', *Loader.load_from_file(tzpath))
169168

170169
raise RuntimeError('Can not find any timezone configuration')
171170

pendulum/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# -*- coding: utf-8 -*-
22

3-
VERSION = '0.5.4'
3+
VERSION = '0.5.5'

tests/fixtures/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# -*- coding: utf-8 -*-
2+

tests/fixtures/tz/Paris

2.9 KB
Binary file not shown.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../usr/share/zoneinfo/Europe/Paris
2.9 KB
Binary file not shown.

0 commit comments

Comments
 (0)