简体   繁体   中英

C# Google Calendar API ignoring Event TimeMin/TimeMax

I am attempting to use the Google .Net Client Libraries to query for Google Calendar events.

I am successfully pulling down events but it seems to completely ignore the TimeMin and TimeMax and return events outside of that time-frame.

As a test, I widened this window from this time yesterday to this time tomorrow with AddDays() .

My code is:

    EventsResource.ListRequest req = service.Events.List(calendarId);

    // Limit the calendar to today
    req.TimeMin = DateTime.Now.AddDays(-1);
    req.TimeMax = DateTime.Now.AddDays(1);

    var events = req.Execute().Items;

For today (11/12/14 ... so 11/11/14 to 11/13/14 using the code above) this is returning events from 11/5/14.

Using the .Net libraries, these two properties are defined as nullable DateTime objects ( DateTime? ), so I am not string-formatting these to any standard.

Am I doing something wrong here?

EDIT: I came across the following link. If this information is true, how exactly would this be handled from .Net where these fields are DateTime? .

/events/list accepts timeMin and timeMax arguments and these are simply stated as accepting a 'datetime' argument. Of the myriad possible standardized date-time formats, I have discovered that this value should be a UTC date-time (with offset explicitly set at 00:00) formatted as RFC3339 (yyyy-MM-ddThh:mm:ss.sss+00:00).

Google Calendar API v3 Undocumentation

I was able to get this to work by setting the SingleEvents property to true.

It seems some of the items that were showing out of the date range were re-occuring events. Setting SingleEvents to true shows the re-occuring event that falls within the date range specified by TimeMin/TimeMax.

    EventsResource.ListRequest req = service.Events.List(calendarId);

    // Limit the calendar to today
    req.TimeMin = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 0, 0, 0);
    req.TimeMax = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 23, 59, 59);

    req.SingleEvents = true;

    var events = req.Execute().Items;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM