Bearon
Bearon

Reputation: 21

How do I make a Google Calendar API event bi-weekly in Reactjs?

 this.state.gapi.auth2
        .getAuthInstance()
        .signIn()
        .then(() => {
          const event = {
            summary: this.state.event.summary,
            location: this.state.event.location,
            description: this.state.event.description,
            start: {
              dateTime: new Date(this.state.start.dateTime),
              timeZone: 'America/Chicago',
            },
            end: {
              dateTime: new Date(this.state.end.dateTime),
              timeZone: 'America/Chicago',
            },
            recurrence: ['RRULE:FREQ=WEEKLY;COUNT=1'],
            reminders: {
              useDefault: false,
              overrides: [
                { method: 'email', minutes: 24 * 60 },
                { method: 'popup', minutes: 10 },
              ],
            },
          };

['RRULE:FREQ=WEEKLY;COUNT=1'], I know this is what's setting that recurrence but I'm not certain how to phrase it for one day every other week.

Upvotes: 1

Views: 544

Answers (2)

Bearon
Bearon

Reputation: 21

I figured it out!!! To set a bi-weekly recurrence on an event you need to set the freq to weekly and then have an interval of 2.

For example my event is every other thursday.

['RRULE:FREQ=WEEKLY;BYDAY=TH;INTERVAL=2']

Upvotes: 1

Tanaike
Tanaike

Reputation: 201473

I thought that in your case, BYDAY might be able to be used. For example, when you want to set the events every Tuesday in the week, RRULE:FREQ=WEEKLY;BYDAY=TU can be used to the value of recurrence. TU is Tuesday. In this case, as the 1st day, the values of dateTime of the start and end are required to be for a day like "2020-12-15T12:00:00" and "2020-12-15T13:00:00" for start and end, respectively. Please be careful this.

As a sample, when you want to set the event from "2020-12-15T12:00:00" to "2020-12-15T13:00:00" every Tuesday in the week and the event is until 20201231, please modify your script as follows.

From:

recurrence: ['RRULE:FREQ=WEEKLY;COUNT=1'],

To:

recurrence: ['RRULE:FREQ=WEEKLY;BYDAY=TU;UNTIL=20201231'],  //  or UNTIL=20201231T000000Z
  • In this case, as the 1st day, please set the values of dateTime of the start and end to "2020-12-15T12:00:00" and "2020-12-15T13:00:00", respectively.
  • And also, UNTIL is used.

References:

  • Events: insert
  • RFC5545

    recurrence[]: List of RRULE, EXRULE, RDATE and EXDATE lines for a recurring event, as specified in RFC5545. Note that DTSTART and DTEND lines are not allowed in this field; event start and end times are specified in the start and end fields. This field is omitted for single events or instances of recurring events.

Upvotes: 1

Related Questions