Skip to content

Commit

Permalink
Merge pull request #117 from evanpurkhiser/black-fns
Browse files Browse the repository at this point in the history
black: Long function defnition arg lists
  • Loading branch information
kiorky authored Oct 30, 2024
2 parents 73a2b9e + 66fccd2 commit 6c54375
Showing 1 changed file with 60 additions and 15 deletions.
75 changes: 60 additions & 15 deletions src/croniter/croniter.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,10 +224,19 @@ class croniter(object):
130
)

def __init__(self, expr_format, start_time=None, ret_type=float,
day_or=True, max_years_between_matches=None, is_prev=False,
hash_id=None, implement_cron_bug=False, second_at_beginning=None,
expand_from_start_time=False):
def __init__(
self,
expr_format,
start_time=None,
ret_type=float,
day_or=True,
max_years_between_matches=None,
is_prev=False,
hash_id=None,
implement_cron_bug=False,
second_at_beginning=None,
expand_from_start_time=False,
):
self._ret_type = ret_type
self._day_or = day_or
self._implement_cron_bug = implement_cron_bug
Expand Down Expand Up @@ -337,7 +346,13 @@ def _timedelta_to_seconds(td):
"""
return timedelta_to_seconds(td)

def _get_next(self, ret_type=None, start_time=None, is_prev=None, update_current=None):
def _get_next(
self,
ret_type=None,
start_time=None,
is_prev=None,
update_current=None,
):
if update_current is None:
update_current = True
self.set_current(start_time, force=True)
Expand Down Expand Up @@ -800,7 +815,13 @@ def value_alias(cls, val, field_index, len_expressions=UNIX_CRON_LEN):
return val

@classmethod
def _expand(cls, expr_format, hash_id=None, second_at_beginning=False, from_timestamp=None):
def _expand(
cls,
expr_format,
hash_id=None,
second_at_beginning=False,
from_timestamp=None,
):
# Split the expression in components, and normalize L -> l, MON -> mon,
# etc. Keep expr_format untouched so we can use it in the exception
# messages.
Expand Down Expand Up @@ -1019,7 +1040,13 @@ def _expand(cls, expr_format, hash_id=None, second_at_beginning=False, from_time
return expanded, nth_weekday_of_month

@classmethod
def expand(cls, expr_format, hash_id=None, second_at_beginning=False, from_timestamp=None):
def expand(
cls,
expr_format,
hash_id=None,
second_at_beginning=False,
from_timestamp=None,
):
"""
Expand a cron expression format into a noramlized format of
list[list[int | 'l' | '*']]. The first list representing each element
Expand Down Expand Up @@ -1088,8 +1115,13 @@ def _get_low_from_current_date_number(cls, field_index, step, from_timestamp):
raise ValueError("Can't get current date number for index larger than 4")

@classmethod
def is_valid(cls, expression, hash_id=None, encoding="UTF-8",
second_at_beginning=False):
def is_valid(
cls,
expression,
hash_id=None,
encoding="UTF-8",
second_at_beginning=False,
):
if hash_id:
if not isinstance(hash_id, (bytes, str)):
raise TypeError("hash_id must be bytes or UTF-8 string")
Expand All @@ -1108,8 +1140,14 @@ def match(cls, cron_expression, testdate, day_or=True, second_at_beginning=False
return cls.match_range(cron_expression, testdate, testdate, day_or, second_at_beginning)

@classmethod
def match_range(cls, cron_expression, from_datetime, to_datetime,
day_or=True, second_at_beginning=False):
def match_range(
cls,
cron_expression,
from_datetime,
to_datetime,
day_or=True,
second_at_beginning=False,
):
cron = cls(cron_expression, to_datetime, ret_type=datetime.datetime,
day_or=day_or, second_at_beginning=second_at_beginning)
tdp = cron.get_current(datetime.datetime)
Expand All @@ -1125,10 +1163,17 @@ def match_range(cls, cron_expression, from_datetime, to_datetime,
return (max(tdp, tdt) - min(tdp, tdt)).total_seconds() < duration_in_second


def croniter_range(start, stop, expr_format, ret_type=None, day_or=True, exclude_ends=False,
_croniter=None,
second_at_beginning=False,
expand_from_start_time=False):
def croniter_range(
start,
stop,
expr_format,
ret_type=None,
day_or=True,
exclude_ends=False,
_croniter=None,
second_at_beginning=False,
expand_from_start_time=False,
):
"""
Generator that provides all times from start to stop matching the given cron expression.
If the cron expression matches either 'start' and/or 'stop', those times will be returned as
Expand Down

0 comments on commit 6c54375

Please sign in to comment.