Refactor next_weekday into Meeting class
Previously, the next_weekday method was the only module level function in the meeting module, and that was the only place it was used. This change incorporates it into the Meeting class since it makes sense to have it there since that's the only thing that uses it. This also touches up the doc strings of next_weekday. Change-Id: I3af654b480c1585ae19841a0baa39079c0ad0d83
This commit is contained in:
parent
7dd6117659
commit
f47bda5e91
@ -82,7 +82,7 @@ class Meeting:
|
||||
|
||||
# get starting date
|
||||
d = datetime.datetime.utcnow()
|
||||
next_meeting = next_weekday(d, const.WEEKDAYS[schedule.day])
|
||||
next_meeting = self._next_weekday(d, const.WEEKDAYS[schedule.day])
|
||||
|
||||
next_meeting_dt = datetime.datetime(next_meeting.year,
|
||||
next_meeting.month,
|
||||
@ -132,11 +132,16 @@ class Meeting:
|
||||
schedule.irc)))
|
||||
return meetings
|
||||
|
||||
def _next_weekday(self, ref_date, weekday):
|
||||
"""Return the date of the next meeting.
|
||||
|
||||
def next_weekday(ref_date, weekday):
|
||||
"""Return the date of the next weekday after ref_date."""
|
||||
:param ref_date: datetime object of meeting
|
||||
:param weekday: weekday the meeting is held on
|
||||
|
||||
days_ahead = weekday - ref_date.weekday()
|
||||
if days_ahead <= 0: # target day already happened this week
|
||||
days_ahead += 7
|
||||
return ref_date + datetime.timedelta(days_ahead)
|
||||
:returns: datetime object of the next meeting time
|
||||
"""
|
||||
|
||||
days_ahead = weekday - ref_date.weekday()
|
||||
if days_ahead <= 0: # target day already happened this week
|
||||
days_ahead += 7
|
||||
return ref_date + datetime.timedelta(days_ahead)
|
||||
|
Loading…
Reference in New Issue
Block a user