Skip to content

Commit b47dc2a

Browse files
author
Sébastien Eustace
committed
Merge branch 'jacebrowning-fix-nonetype-transition'
2 parents d78b4c4 + 0753a3f commit b47dc2a

File tree

2 files changed

+26
-20
lines changed

2 files changed

+26
-20
lines changed

pendulum/tz/timezone.py

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -107,25 +107,26 @@ def _normalize(self, dt, dst_rule=None): # type: (_D, Optional[str]) -> _D
107107
else:
108108
transition = transition.previous
109109

110-
if transition.is_ambiguous(sec):
111-
# Ambiguous time
112-
if dst_rule == TRANSITION_ERROR:
113-
raise AmbiguousTime(dt)
114-
115-
# We set the fold attribute for later
116-
if dst_rule == POST_TRANSITION:
117-
fold = 1
118-
elif transition.is_missing(sec):
119-
# Skipped time
120-
if dst_rule == TRANSITION_ERROR:
121-
raise NonExistingTime(dt)
122-
123-
# We adjust accordingly
124-
if dst_rule == POST_TRANSITION:
125-
sec += transition.fix
126-
fold = 1
127-
else:
128-
sec -= transition.fix
110+
if transition:
111+
if transition.is_ambiguous(sec):
112+
# Ambiguous time
113+
if dst_rule == TRANSITION_ERROR:
114+
raise AmbiguousTime(dt)
115+
116+
# We set the fold attribute for later
117+
if dst_rule == POST_TRANSITION:
118+
fold = 1
119+
elif transition.is_missing(sec):
120+
# Skipped time
121+
if dst_rule == TRANSITION_ERROR:
122+
raise NonExistingTime(dt)
123+
124+
# We adjust accordingly
125+
if dst_rule == POST_TRANSITION:
126+
sec += transition.fix
127+
fold = 1
128+
else:
129+
sec -= transition.fix
129130

130131
kwargs = {"tzinfo": self}
131132
if _HAS_FOLD or isinstance(dt, pendulum.DateTime):

tests/date/test_sub.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import pendulum
44

5-
from datetime import timedelta
5+
from datetime import datetime, timedelta
66

77
from ..conftest import assert_date
88

@@ -43,6 +43,11 @@ def test_subtract_days_negative():
4343
assert pendulum.Date(1975, 5, 30).subtract(days=-1).day == 31
4444

4545

46+
def test_subtract_days_max():
47+
delta = pendulum.now() - pendulum.instance(datetime.min)
48+
assert pendulum.now().subtract(days=delta.days - 1).year == 1
49+
50+
4651
def test_subtract_weeks_positive():
4752
assert pendulum.Date(1975, 5, 28).subtract(weeks=1).day == 21
4853

0 commit comments

Comments
 (0)