简体   繁体   English

C#Google Calendar API忽略事件TimeMin / TimeMax

[英]C# Google Calendar API ignoring Event TimeMin/TimeMax

I am attempting to use the Google .Net Client Libraries to query for Google Calendar events. 我正在尝试使用Google .Net客户端库查询Google日历事件。

I am successfully pulling down events but it seems to completely ignore the TimeMin and TimeMax and return events outside of that time-frame. 我已成功取消事件,但它似乎完全忽略了TimeMin和TimeMax并在该时间范围之外返回事件。

As a test, I widened this window from this time yesterday to this time tomorrow with AddDays() . 作为测试,我使用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. 对于今天(11/12/14 ...所以11/11/14至11/13/14,使用上面的代码),这是从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. 使用.Net库,这两个属性被定义为可为null的DateTime对象( DateTime? ),因此我没有将其字符串格式化为任何标准。

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? 如果此信息为真,那么如何从.Net(这些字段为DateTime?正确处理DateTime? .

/events/list accepts timeMin and timeMax arguments and these are simply stated as accepting a 'datetime' argument. / events / list接受timeMin和timeMax参数,它们被简单地表示为接受“ datetime”参数。 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). 在众多可能的标准化日期时间格式中,我发现此值应为UTC日期时间(偏移量明确设置为00:00),格式为RFC3339(yyyy-MM-ddThh:mm:ss.sss + 00 :00)。

Google Calendar API v3 Undocumentation Google Calendar API v3取消文档编制

I was able to get this to work by setting the SingleEvents property to true. 我可以通过将SingleEvents属性设置为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. 将SingleEvents设置为true将显示属于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;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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