Search code examples
xmlgoogle-calendar-apirfc2445rfc5545

Adding recurring event to Google Calendar via XML


I am trying to add a recurring event to my calendar via the Protocol API. I took the syntax of the recurrence tag from an event I created in Google's interface and used that in my create request. Here is what I submitted:

<?xml version='1.0' encoding='utf-8' ?> 
<entry xmlns='http://www.w3.org/2005/Atom' xmlns:gd='http://schemas.google.com/g/2005'> 
    <category scheme='http://schemas.google.com/g/2005#kind' term='http://schemas.google.com/g/2005#event'></category> 
    <title type='text'>Hi Stack Overflow!</title> 
    <content type='text'>Help me please!</content> 
    <gd:where valueString='StackOverflow.com'></gd:where> 
    <gd:recurrence>
        DTSTART;TZID=America/Los_Angeles:20090824T080000
        DTEND;TZID=America/Los_Angeles:20090824T090000 
        RRULE:FREQ=DAILY;WKST=SU;UNTIL=20090828T090000 
        BEGIN:VTIMEZONE TZID:America/Los_Angeles X-LIC-LOCATION:America/Los_Angeles 
        BEGIN:DAYLIGHT TZOFFSETFROM:-0800 TZOFFSETTO:-0700 TZNAME:PDT DTSTART:19700308T020000 
        RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=2SU 
        END:DAYLIGHT 
        BEGIN:STANDARD TZOFFSETFROM:-0700 TZOFFSETTO:-0800 TZNAME:PST DTSTART:19701101T020000 
        RRULE:FREQ=YEARLY;BYMONTH=11;BYDAY=1SU 
        END:STANDARD 
        END:VTIMEZONE
    </gd:recurrence> 
 </entry>

The event is added, but it does not repeat. When I look at the recurrence section of the resulting event feed, the RRULE that defines the repeating is not there.

Thank you for any help!


Solution

  • Two things:

    1. Your timezone section isn't valid - I believe each property should be on a line on its own.

    2. Your "UNTIL" should be a UTC time. From RFC2445:

    If specified as a date-time value, then it MUST be specified in an UTC time format.

    So here's a complete example, having adjusted the local time to UTC for the "until" part, and expanded the time zone:

    DTSTART;TZID=America/Los_Angeles:20090824T080000
    DTEND;TZID=America/Los_Angeles:20090824T090000 
    RRULE:FREQ=DAILY;WKST=SU;UNTIL=20090828T160000Z
    BEGIN:VTIMEZONE
    TZID:America/Los_Angeles
    X-LIC-LOCATION:America/Los_Angeles 
    BEGIN:DAYLIGHT
    TZOFFSETFROM:-0800
    TZOFFSETTO:-0700
    TZNAME:PDT
    DTSTART:19700308T020000 
    RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=2SU 
    END:DAYLIGHT 
    BEGIN:STANDARD
    TZOFFSETFROM:-0700
    TZOFFSETTO:-0800
    TZNAME:PST
    DTSTART:19701101T020000 
    RRULE:FREQ=YEARLY;BYMONTH=11;BYDAY=1SU 
    END:STANDARD 
    END:VTIMEZONE
    

    I have a sneaking suspicion this may have been a recent change.

    Alternatively, you might want to try omitting the VTIMEZONE section entirely - just supply the TZID, which should be an ID that you know Google Calendar supports. For example:

    DTSTART;TZID=America/Los_Angeles:20090824T080000
    DTEND;TZID=America/Los_Angeles:20090824T090000 
    RRULE:FREQ=DAILY;WKST=SU;UNTIL=20090828T160000Z