Skip to content

Commit 89e9ac2

Browse files
neonquillsdispater
authored andcommitted
When creating without tzinfo, preserve fold. (#108)
When creating a new Pendulum instance without passing in a TimezoneInfo object and using python 3.6, the internal fold parameter was not correct. In this scenario, self._fold was being set based on the fold parameter in the underlying datetime object. When using python3.6, this value exists, but is always set to 0 since Pendulum is not passing the fold parameter to the constructor. - Changed self._fold to always be set based on the internal fold variable. - Added checks to the existing unit tests to verify that the fold parameter is being preserved.
1 parent 7a496ec commit 89e9ac2

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

pendulum/pendulum.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ def __init__(self, year, month, day,
176176
self._second = dt.second
177177
self._microsecond = dt.microsecond
178178
self._tzinfo = dt.tzinfo
179-
self._fold = getattr(dt, 'fold', fold)
179+
self._fold = fold
180180

181181
self._timestamp = None
182182
self._int_timestamp = None

tests/pendulum_tests/test_construct.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,8 @@ def test_init_fold_is_honored_if_explicit(self):
202202

203203
d = Pendulum(2013, 3, 31, 2, 30, tzinfo='Europe/Paris', fold=0)
204204
self.assertPendulum(d, 2013, 3, 31, 1, 30)
205+
self.assertEqual(d.fold, 0)
205206

206207
d = Pendulum(2013, 3, 31, 2, 30, tzinfo='Europe/Paris', fold=1)
207208
self.assertPendulum(d, 2013, 3, 31, 3, 30)
209+
self.assertEqual(d.fold, 1)

0 commit comments

Comments
 (0)