Skip to content

Commit

Permalink
Make helper instance methods that do not use self static
Browse files Browse the repository at this point in the history
  • Loading branch information
evanpurkhiser committed Oct 30, 2024
1 parent 010b321 commit 93e703b
Showing 1 changed file with 14 additions and 9 deletions.
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

0 comments on commit 93e703b

Please sign in to comment.