1 #!/usr/bin/env python 2 3 """ 4 Test objects. 5 6 Copyright (C) 2017 Paul Boddie <paul@boddie.org.uk> 7 8 This program is free software; you can redistribute it and/or modify it under 9 the terms of the GNU General Public License as published by the Free Software 10 Foundation; either version 3 of the License, or (at your option) any later 11 version. 12 13 This program is distributed in the hope that it will be useful, but WITHOUT 14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 15 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 16 details. 17 18 You should have received a copy of the GNU General Public License along with 19 this program. If not, see <http://www.gnu.org/licenses/>. 20 """ 21 22 from imiptools.data import parse_string, Object 23 from imiptools.dates import get_datetime 24 25 # Define a parent object plus recurrence instances. 26 27 parent_str = """\ 28 BEGIN:VEVENT 29 ORGANIZER:mailto:paul.boddie@example.com 30 ATTENDEE;RSVP=TRUE:mailto:resource-room-confroom@example.com 31 DTSTAMP:20141009T182400Z 32 DTSTART;TZID=Europe/Oslo:20141010 33 DTEND;TZID=Europe/Oslo:20141011 34 RRULE:FREQ=MONTHLY;BYDAY=2FR;COUNT=3 35 SUMMARY:Recurring event 36 UID:event4@example.com 37 END:VEVENT 38 """ 39 40 modification_str = """\ 41 BEGIN:VEVENT 42 ORGANIZER:mailto:paul.boddie@example.com 43 ATTENDEE;RSVP=TRUE:mailto:resource-room-confroom@example.com 44 DTSTAMP:20141009T182500Z 45 DTSTART;TZID=Europe/Oslo:20141115 46 DTEND;TZID=Europe/Oslo:20141116 47 SUMMARY:Recurring event 48 UID:event4@example.com 49 RECURRENCE-ID;TZID=Europe/Oslo:20141114 50 SEQUENCE:2 51 END:VEVENT 52 """ 53 54 cancellation_str = """\ 55 BEGIN:VEVENT 56 ORGANIZER:mailto:paul.boddie@example.com 57 ATTENDEE;RSVP=TRUE:mailto:resource-room-confroom@example.com 58 DTSTAMP:20141009T182500Z 59 DTSTART;TZID=Europe/Oslo:20141212 60 DTEND;TZID=Europe/Oslo:20141213 61 SUMMARY:Recurring event 62 UID:event4@example.com 63 RECURRENCE-ID;TZID=Europe/Oslo:20141212 64 SEQUENCE:2 65 END:VEVENT 66 """ 67 68 # Parse the objects. 69 70 parent = Object(parse_string(parent_str, "utf-8")) 71 modification = Object(parse_string(modification_str, "utf-8")) 72 cancellation = Object(parse_string(cancellation_str, "utf-8")) 73 74 # Set the recurrence objects in the parent. 75 76 parent.set_modifying([modification]) 77 parent.set_cancelling([cancellation]) 78 79 # Obtain periods within a window of time. 80 81 tzid = parent.get_tzid() 82 start = get_datetime("20141001T000000", {"TZID" : tzid}) 83 end = get_datetime("20151001", {"TZID" : tzid}) 84 85 for p in parent.get_periods(start, end): 86 print p 87 88 print "----" 89 90 for old, new in parent.get_updated_periods(start, end): 91 print old 92 print new 93 print 94 95 print "----" 96 97 for p in parent.get_active_periods(start, end): 98 print p 99 100 # vim: tabstop=4 expandtab shiftwidth=4