From 93e703b3f959b1ca6e0dc6f3293b3116fd523b7d Mon Sep 17 00:00:00 2001 From: Evan Purkhiser Date: Tue, 29 Oct 2024 18:47:58 -0400 Subject: [PATCH] Make helper instance methods that do not use self static --- src/croniter/croniter.py | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/croniter/croniter.py b/src/croniter/croniter.py index 54dbeb0..cae15bb 100644 --- a/src/croniter/croniter.py +++ b/src/croniter/croniter.py @@ -317,8 +317,8 @@ def set_current(self, start_time, force=True): self.cur = start_time return self.cur - @classmethod - def _datetime_to_timestamp(cls, d): + @staticmethod + def _datetime_to_timestamp(d): """ Converts a `datetime` object `d` into a UNIX timestamp. """ @@ -339,8 +339,8 @@ def _timestamp_to_datetime(self, timestamp): return result - @classmethod - def _timedelta_to_seconds(cls, td): + @staticmethod + def _timedelta_to_seconds(td): """ Converts a 'datetime.timedelta' object `td` into seconds contained in the duration. @@ -705,13 +705,15 @@ def proc_second(d): raise CroniterBadDateError("failed to find prev date") raise CroniterBadDateError("failed to find next date") - def _get_next_nearest(self, x, to_check): + @staticmethod + def _get_next_nearest(x, to_check): small = [item for item in to_check if item < x] large = [item for item in to_check if item >= x] large.extend(small) return large[0] - def _get_prev_nearest(self, x, to_check): + @staticmethod + def _get_prev_nearest(x, to_check): small = [item for item in to_check if item <= x] large = [item for item in to_check if item > x] small.reverse() @@ -719,7 +721,8 @@ def _get_prev_nearest(self, x, to_check): small.extend(large) return small[0] - def _get_next_nearest_diff(self, x, to_check, range_val): + @staticmethod + def _get_next_nearest_diff(x, to_check, range_val): """ `range_val` is the range of a field. If no available time, we can move to next loop(like next month). @@ -739,7 +742,8 @@ def _get_next_nearest_diff(self, x, to_check, range_val): return None return to_check[0] - x + range_val - def _get_prev_nearest_diff(self, x, to_check, range_val): + @staticmethod + def _get_prev_nearest_diff(x, to_check, range_val): """ `range_val` is the range of a field. If no available time, we can move to previous loop(like previous month). @@ -785,7 +789,8 @@ def _get_nth_weekday_of_month(year, month, day_of_week): c.pop(0) return tuple(i[0] for i in c) - def is_leap(self, year): + @staticmethod + def is_leap(year): if year % 400 == 0 or (year % 4 == 0 and year % 100 != 0): return True else: