Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make helper instance methods that do not use self static #106

Merged
merged 1 commit into from
Oct 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 14 additions & 9 deletions src/croniter/croniter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
"""
Expand All @@ -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.
Expand Down Expand Up @@ -705,21 +705,24 @@ 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()
large.reverse()
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).
Expand All @@ -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).
Expand Down Expand Up @@ -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:
Expand Down
Loading