From f47bda5e91c417a0c700b6960a35598da80ccf4c Mon Sep 17 00:00:00 2001 From: Lance Bragstad Date: Sat, 31 May 2014 02:31:32 +0000 Subject: [PATCH] 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 --- arbiter/meeting.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/arbiter/meeting.py b/arbiter/meeting.py index 6fc8a33..392a754 100644 --- a/arbiter/meeting.py +++ b/arbiter/meeting.py @@ -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)