diff --git a/yaml2ical/recurrence.py b/yaml2ical/recurrence.py index 7032ec7..e31186e 100644 --- a/yaml2ical/recurrence.py +++ b/yaml2ical/recurrence.py @@ -39,6 +39,19 @@ class _Recurrence(object, metaclass=abc.ABCMeta): def __str__(self): "Return string representation of the recurrence rule" + @property + def day_specifier(self): + """Return string prefix for day. + + For example, monthly recurring events may return 'first' to + indicate the first instance of a particular day of the month + (e.g., first Thursday). + """ + # NOTE(dhellmann): This is not an abstract property because + # most of the subclasses will use this concrete + # implementation. + return '' + class WeeklyRecurrence(_Recurrence): """Meetings occuring every week.""" @@ -213,6 +226,18 @@ class MonthlyRecurrence(_Recurrence): def __str__(self): return "Monthly" + _ORDINALS = [ + 'first', + 'second', + 'third', + 'fourth', + 'fifth', + ] + + @property + def day_specifier(self): + return 'the {}'.format(self._ORDINALS[self._week - 1]) + supported_recurrences = { 'weekly': WeeklyRecurrence(), diff --git a/yaml2ical/tests/test_recurrence.py b/yaml2ical/tests/test_recurrence.py index 11413f3..20259a6 100644 --- a/yaml2ical/tests/test_recurrence.py +++ b/yaml2ical/tests/test_recurrence.py @@ -105,3 +105,15 @@ class RecurrenceTestCase(unittest.TestCase): self.next_meeting, rec, ) + + def test_monthly_day_specifier(self): + weeks = [ + (1, 'the first'), + (2, 'the second'), + (3, 'the third'), + (4, 'the fourth'), + (5, 'the fifth'), + ] + for i, expected in weeks: + rec = recurrence.MonthlyRecurrence(week=i, day='Thursday') + self.assertEqual(expected, rec.day_specifier)