File tree Expand file tree Collapse file tree 2 files changed +26
-20
lines changed Expand file tree Collapse file tree 2 files changed +26
-20
lines changed Original file line number Diff line number Diff line change @@ -108,25 +108,26 @@ def _normalize(
108108 else :
109109 transition = transition .previous
110110
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
111+ if transition :
112+ if transition .is_ambiguous (sec ):
113+ # Ambiguous time
114+ if dst_rule == TRANSITION_ERROR :
115+ raise AmbiguousTime (dt )
116+
117+ # We set the fold attribute for later
118+ if dst_rule == POST_TRANSITION :
119+ fold = 1
120+ elif transition .is_missing (sec ):
121+ # Skipped time
122+ if dst_rule == TRANSITION_ERROR :
123+ raise NonExistingTime (dt )
124+
125+ # We adjust accordingly
126+ if dst_rule == POST_TRANSITION :
127+ sec += transition .fix
128+ fold = 1
129+ else :
130+ sec -= transition .fix
130131
131132 kwargs = {"tzinfo" : self }
132133 if _HAS_FOLD or isinstance (dt , pendulum .DateTime ):
Original file line number Diff line number Diff line change 22
33import pendulum
44
5- from datetime import timedelta
5+ from datetime import datetime , timedelta
66
77from ..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+
4651def test_subtract_weeks_positive ():
4752 assert pendulum .Date (1975 , 5 , 28 ).subtract (weeks = 1 ).day == 21
4853
You can’t perform that action at this time.
0 commit comments