Skip to content

Commit

Permalink
Implement LastNDayOfMonthExpression
Browse files Browse the repository at this point in the history
  • Loading branch information
Xu Jay committed Nov 14, 2024
1 parent 497cb96 commit 440226a
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/apscheduler/triggers/cron/expressions.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,15 +256,15 @@ def __str__(self) -> str:
class LastNDayOfMonthExpression(AllExpression):
value_re = re.compile(r"last-(?P<last_day>[0-9]+)", re.IGNORECASE)

def __init__(self, last_day):
def __init__(self, last_day: str):
super().__init__(None)
self.last_day = as_int(last_day)

def get_next_value(self, date, field):
currval = field.get_value(date)
nextval = monthrange(date.year, date.month)[1] - self.last_day
def get_next_value(self, dateval: datetime, field: BaseField) -> int | None:
currval = field.get_value(dateval)
nextval = monthrange(dateval.year, dateval.month)[1] - self.last_day

return nextval if currval <= nextval else None

def __str__(self):
def __str__(self) -> str:
return f"last-{self.last_day}"

0 comments on commit 440226a

Please sign in to comment.