From a8c789d4b492d56775869da65d4e71b45ea8a5c9 Mon Sep 17 00:00:00 2001 From: "Brian (bex) Exelbierd" Date: Wed, 24 Jun 2015 20:39:53 +0200 Subject: [PATCH] start_date now supported in schedules start_date defines when a meeting series begins. start_date is used in lieu of the current date when rebuilding the calendar. This will ultimately let us move away from needing to have biweekly-odd and biweekly-even. I also added an example.yaml with a start_date Change-Id: I0c5f6e5951b6c15b949f599182f48aa132b76abb --- README.rst | 2 ++ meetings/{example.yaml => example1.yaml} | 0 meetings/example2.yaml | 13 ++++++++++ yaml2ical/ical.py | 4 ++-- yaml2ical/meeting.py | 11 +++++++++ yaml2ical/tests/sample_data.py | 16 +++++++++++++ yaml2ical/tests/test_meeting_recurrence.py | 28 ++++++++++++++++++++++ 7 files changed, 72 insertions(+), 2 deletions(-) rename meetings/{example.yaml => example1.yaml} (100%) create mode 100644 meetings/example2.yaml create mode 100644 yaml2ical/tests/test_meeting_recurrence.py diff --git a/README.rst b/README.rst index 22b7b79..c37e63f 100644 --- a/README.rst +++ b/README.rst @@ -122,6 +122,8 @@ Each meeting consists of: * ``time``: time string in UTC [MANDATORY] * ``duration``: duration of the meeting in minutes; defaults to 60 + * ``start_date``: the date the first meeting takes place on or after. + Format `YYYYMMDD`, all values must be zero-padded. * ``day``: the day of week the meeting takes place [MANDATORY] * ``irc``: the irc room in which the meeting is held [MANDATORY] * ``frequency``: frequent occurrence of the meeting [MANDATORY] diff --git a/meetings/example.yaml b/meetings/example1.yaml similarity index 100% rename from meetings/example.yaml rename to meetings/example1.yaml diff --git a/meetings/example2.yaml b/meetings/example2.yaml new file mode 100644 index 0000000..fe76f50 --- /dev/null +++ b/meetings/example2.yaml @@ -0,0 +1,13 @@ +project: Example Start Date Team Meeting +agenda_url: http://agenda.com/ +project_url: http://project.com +schedule: + - time: '1600' + duration: 45 + start_date: 20150801 + day: Thursday + irc: openstack-meeting + frequency: weekly +chair: John Doe +description: > + If you're interested in Example, we have a 45 minute long weekly meeting for you to attend. diff --git a/yaml2ical/ical.py b/yaml2ical/ical.py index cf6053b..5632eb5 100644 --- a/yaml2ical/ical.py +++ b/yaml2ical/ical.py @@ -63,8 +63,8 @@ class Yaml2IcalCalendar(icalendar.Calendar): event.add('description', ical_descript) # get starting date - start_date = datetime.datetime.utcnow() - next_meeting = sch.recurrence.next_occurence(start_date, sch.day) + next_meeting = sch.recurrence.next_occurence(sch.start_date, + sch.day) next_meeting_date = datetime.datetime(next_meeting.year, next_meeting.month, next_meeting.day, diff --git a/yaml2ical/meeting.py b/yaml2ical/meeting.py index 8b80586..efeeaba 100644 --- a/yaml2ical/meeting.py +++ b/yaml2ical/meeting.py @@ -53,6 +53,17 @@ class Schedule(object): "attribute '{0}'".format(e.args[0])) raise + # optional: start_date defaults to the current date if not present + if 'start_date' in sched_yaml: + try: + self.start_date = datetime.datetime.strptime( + str(sched_yaml['start_date']), '%Y%m%d') + except ValueError: + raise ValueError("Could not parse 'start_date' (%s) in %s" % + (sched_yaml['start_date'], self.filefrom)) + else: + self.start_date = datetime.datetime.utcnow() + # optional: duration if 'duration' in sched_yaml: try: diff --git a/yaml2ical/tests/sample_data.py b/yaml2ical/tests/sample_data.py index 83df53d..cfd9c86 100644 --- a/yaml2ical/tests/sample_data.py +++ b/yaml2ical/tests/sample_data.py @@ -176,3 +176,19 @@ description: > agenda: | * Debate whether this should be a longer meeting """ + +MEETING_WITH_START_DATE = """ +project: OpenStack Subteam 8 Meeting +schedule: + - time: '1200' + duration: 30 + day: Thursday + start_date: 20150801 + irc: openstack-meeting + frequency: weekly +chair: Shannon Stacker +description: > + Weekly short meeting for Subteam project. +agenda: | + * Debate whether this should be a longer meeting +""" diff --git a/yaml2ical/tests/test_meeting_recurrence.py b/yaml2ical/tests/test_meeting_recurrence.py new file mode 100644 index 0000000..b61abeb --- /dev/null +++ b/yaml2ical/tests/test_meeting_recurrence.py @@ -0,0 +1,28 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +import datetime +import unittest + +from yaml2ical import meeting +from yaml2ical import recurrence +from yaml2ical.tests import sample_data + + +class Meeting_RecurrenceTestCase(unittest.TestCase): + + def test_next_meeting_start_date(self): + m = meeting.load_meetings(sample_data.MEETING_WITH_START_DATE)[0] + self.assertEqual( + datetime.datetime(2015, 8, 6, 0, 0), + recurrence.WeeklyRecurrence().next_occurence( + m.schedules[0].start_date, m.schedules[0].day))