Get events of a specific time range

柔情痞子 提交于 2020-01-07 03:08:08

问题


I'm working with the Office365 Outlook Calendar API. I need to get events of a specific time range. I tried to compare the DateTimeTimeZone values inside of the foreach command, but it seems like it only supports a == operator:

if ( calendarEvent.Start >= new DateTimeTimeZone()
            {
                TimeZone = TimeZoneInfo.Local.Id,
                DateTime = DateTime.Now.ToString("s")
            })

This code snippet fails with the error: Cannot apply operator '>=' to operands of type 'Microsoft.Office365.OutlookServices.DateTimeTimeZone' and 'Microsoft.Office365.OutlookServices.DateTimeTimeZone'

Are there any other ways get events of a specific time range, e.g. future events?

This is my GetEvents()-method so far:

    [Route("GetEvents")]
    public async Task GetEvents()
    {
        //Get client
        OutlookServicesClient client = await this.GetClient();

        //Get events
        var events = await client.Me.Events
            .Take(10)
            .ExecuteAsync();

        foreach (var calendarEvent in events.CurrentPage)
        {
            //
            if ( calendarEvent.Subject == "Test 1" )
            {
                System.Diagnostics.Debug.WriteLine("Event '{0}'.", calendarEvent.Subject) ; 
            }
        }
    }

回答1:


You should use the CalendarView to get events within a time range.

DateTimeOffset startDateTime, endDateTime;
var events = client.Me.GetCalendarView(startDateTime, endDateTime);


来源:https://stackoverflow.com/questions/34708747/get-events-of-a-specific-time-range

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!