Skip to content

Commit

Permalink
Eliminate self.forward, use self.tick_direction only
Browse files Browse the repository at this point in the history
  • Loading branch information
cuu508 committed Nov 1, 2024
1 parent 1b47583 commit 9a8e134
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions cronsim/cronsim.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,6 @@ class CronSim(object):

def __init__(self, expr: str, dt: datetime, forward: bool = True):
self.dt = dt.replace(second=0, microsecond=0)
self.forward = forward
self.tick_direction = 1 if forward else -1

self.parts = expr.upper().split()
Expand Down Expand Up @@ -349,7 +348,7 @@ def reverse_day(self) -> bool:

month = needle.month
while not self.match_day(needle):
needle += td(days=-1)
needle -= td(days=1)
if needle.month != month:
# We're in a different month now, break out to re-check month
# This significantly speeds up the "0 0 * 2 MON#5" case
Expand Down Expand Up @@ -440,7 +439,7 @@ def reverse(self) -> None:
def __next__(self) -> datetime:
self.tick()

if self.forward:
if self.tick_direction == 1:
self.advance()
else:
self.reverse()
Expand Down

0 comments on commit 9a8e134

Please sign in to comment.