0

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) ; 
            }
        }
    }
Konstantin Kreft
  • 613
  • 5
  • 18
  • try to put the new DateTimeTimeZone() in an variable and then check for the condition using that variable – Sundar Rajan Jan 11 '16 at 09:54
  • Please see ["Should questions include “tags” in their titles?"](http://meta.stackexchange.com/questions/19190/should-questions-include-tags-in-their-titles), where the consensus is "no, they should not"! –  Jan 11 '16 at 15:26

1 Answers1

1

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

DateTimeOffset startDateTime, endDateTime;
var events = client.Me.GetCalendarView(startDateTime, endDateTime);
Jason Johnston
  • 17,194
  • 2
  • 20
  • 34