Skip to content

Commit

Permalink
Merge pull request #125 from evanpurkhiser/black-expressions
Browse files Browse the repository at this point in the history
black: Expression formatting
  • Loading branch information
kiorky authored Oct 30, 2024
2 parents 0eac281 + 3b792ec commit 0a75315
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions src/croniter/croniter.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,8 @@ def __init__(
hash_id = hash_id.encode("UTF-8")

self._max_years_btw_matches_explicitly_set = (
max_years_between_matches is not None)
max_years_between_matches is not None
)
if not self._max_years_btw_matches_explicitly_set:
max_years_between_matches = 50
self._max_years_between_matches = max(int(max_years_between_matches), 1)
Expand Down Expand Up @@ -419,20 +420,15 @@ def _get_next(

# DST Handling for cron job spanning across days
dtstarttime = self._timestamp_to_datetime(self.dst_start_time)
dtstarttime_utcoffset = (
dtstarttime.utcoffset() or datetime.timedelta(0))
dtstarttime_utcoffset = dtstarttime.utcoffset() or datetime.timedelta(0)
dtresult = self._timestamp_to_datetime(result)
lag = lag_hours = 0
# do we trigger DST on next crontab (handle backward changes)
dtresult_utcoffset = dtstarttime_utcoffset
if dtresult and self.tzinfo:
dtresult_utcoffset = dtresult.utcoffset()
lag_hours = (
self._timedelta_to_seconds(dtresult - dtstarttime) / (60 * 60)
)
lag = self._timedelta_to_seconds(
dtresult_utcoffset - dtstarttime_utcoffset
)
lag_hours = self._timedelta_to_seconds(dtresult - dtstarttime) / (60 * 60)
lag = self._timedelta_to_seconds(dtresult_utcoffset - dtstarttime_utcoffset)
hours_before_midnight = 24 - dtstarttime.hour
if dtresult_utcoffset != dtstarttime_utcoffset:
if (lag > 0 and abs(lag_hours) >= hours_before_midnight) or (
Expand Down Expand Up @@ -502,7 +498,7 @@ def all_prev(self, ret_type=None, start_time=None, update_current=None):
raise

def iter(self, *args, **kwargs):
return (self._is_prev and self.all_prev or self.all_next)
return self._is_prev and self.all_prev or self.all_next

def __iter__(self):
return self
Expand Down Expand Up @@ -816,8 +812,8 @@ def _get_prev_nearest_diff(x, to_check, range_val):
if candidate > range_val:
# fix crontab "0 6 30 3 *" condidates only a element,
# then get_prev error return 2021-03-02 06:00:00
return - x
return (candidate - x - range_val)
return -x
return candidate - x - range_val

@staticmethod
def _get_nth_weekday_of_month(year, month, day_of_week):
Expand Down Expand Up @@ -935,7 +931,7 @@ def _expand(
e = he
try:
nth = int(last)
assert (nth >= 1 and nth <= 5)
assert nth >= 1 and nth <= 5
except (KeyError, ValueError, AssertionError):
raise CroniterBadCronError(
"[{0}] is not acceptable. Invalid day_of_week "
Expand Down Expand Up @@ -998,7 +994,10 @@ def _expand(
)
)

low, high = [cls.value_alias(int(_val), field_index, expressions) for _val in (low, high)]
low, high = [
cls.value_alias(int(_val), field_index, expressions)
for _val in (low, high)
]

if max(low, high) > max(
cls.RANGES[field_index][0], cls.RANGES[field_index][1]
Expand Down Expand Up @@ -1283,7 +1282,10 @@ def croniter_range(
"The start and stop must be same type. {0} != {1}".
format(type(start), type(stop)))
if isinstance(start, (float, int)):
start, stop = (datetime.datetime.fromtimestamp(t, tzutc()).replace(tzinfo=None) for t in (start, stop))
start, stop = (
datetime.datetime.fromtimestamp(t, tzutc()).replace(tzinfo=None)
for t in (start, stop)
)
auto_rt = float
if ret_type is None:
ret_type = auto_rt
Expand Down

0 comments on commit 0a75315

Please sign in to comment.