Home > Net >  c# using Google.Apis.Calendar.v3 create meeting for next month every weekday 30 min event
c# using Google.Apis.Calendar.v3 create meeting for next month every weekday 30 min event

Time:11-02

I want to create daily weekdays event for 30 minit. it seems there is something wrong in

Recurrence = new String[] { "RRULE:FREQ=MONTHLY;BYDAY=MO,TU,WE,TH,FR;UNTIL="   nextmonthlastdayString   "T040000Z" },

I am not able to find solution tried many things.

 public async Task<ActionResult> NewEvent()
    {
        var credential = await GetCredentialForApiAsync();

        var initializer = new BaseClientService.Initializer()
        {
            HttpClientInitializer = credential,
            ApplicationName = "ASP.NET MVC5 Calendar Sample",
        };

        var service = new CalendarService(initializer);
        var today = DateTime.Now;
        var nextmonth = today.AddMonths(1).AddDays(-today.Day   1);
        var nextmonthString = nextmonth.ToString("yyyyMMdd");
        var nxtmonthLastDate= DateTime.DaysInMonth(nextmonth.Year, nextmonth.Month);
        DateTime lastDayNextMonth = nextmonth.AddDays(-nextmonth.Day   nxtmonthLastDate);
        var nextmonthlastdayString = lastDayNextMonth.ToString("yyyyMMdd");


        var lastDayofMonthString = DateTime.DaysInMonth(nextmonth.Year, nextmonth.Month).ToString(nextmonth.Year   ""   nextmonth.Month   ""   nextmonth.Day);

        DateTime start = DateTime.Now;
        DateTime end = start   TimeSpan.FromMinutes(30);
        //start = DateTime.SpecifyKind(start, DateTimeKind.Local);
        //end = DateTime.SpecifyKind(end, DateTimeKind.Local);


        Event newEvent = new Event()
        {
            Summary = " Dealer Meeting",
            Location = "1600 Amphitheatre Parkway., Mountain View, CA 94043",
            Description = "A chance to learn more about Google APIs.",
         
            Start = new EventDateTime()
            {
                DateTime = nextmonth,
                TimeZone = "Asia/Kolkata",
            },
            End = new EventDateTime()
            {
                DateTime = lastDayNextMonth,
                TimeZone = "Asia/Kolkata",
            },

            //Recurrence = new String[] { "RRULE:FREQ=DAILY;COUNT=5" },

            //Recurrence = new String[] { "RRULE:FREQ=WEEKLY;BYDAY=MO,TU,WE,TH,FR;UNTIL="  nextmonth   "T040000Z" },
            Recurrence = new String[] { "RRULE:FREQ=MONTHLY;BYDAY=MO,TU,WE,TH,FR;UNTIL="   nextmonthlastdayString   "T040000Z" },
            Attendees = new EventAttendee[] {
                new EventAttendee() { Email = "[email protected]" },
            },
            Reminders = new Event.RemindersData()
            {
                UseDefault = false,
                Overrides = new EventReminder[] {
                    new EventReminder() { Method = "email", Minutes = 24 * 60 },
                    new EventReminder() { Method = "sms", Minutes = 10 },
            }
            }
        };

        String calendarId = "primary";
        EventsResource.InsertRequest request = service.Events.Insert(newEvent, calendarId);
        Event createdEvent = request.Execute();
        return View();
    }

CodePudding user response:

Your RRULE is correct, the problem is theend date

As per documentation:

end

The (exclusive) end time of the event. For a recurring event, this is the end time of the first instance.

This means that you should modify

            {
                DateTime = lastDayNextMonth,
                TimeZone = "Asia/Kolkata",
            }

to

            End = new EventDateTime()
            {
                DateTime = start   TimeSpan.FromMinutes(30),
                TimeZone = "Asia/Kolkata",
            }

Sample:

            Start = new EventDateTime()
            {
                DateTime = "2021-11-01T09:00:00",
                TimeZone = "Asia/Kolkata",
            }
            End = new EventDateTime()
            {
                DateTime = "2021-11-01T09:30:00",
                TimeZone = "Asia/Kolkata",
            }
  • Related