c# 使用 Google.Apis.Calendar.v3 创建下个月每个工作日 30 分钟活动的会议

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

我想创建 30 分钟的每日工作日活动。

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

我尝试了很多方法都找不到解决方案。

 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 = "test@test.com" },
            },
            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();
    }

您的 RRULE 是正确的,问题是 end 日期

根据documentation

end

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

这意味着你应该修改

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

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

样本:

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