C# Google 日历 API 忽略事件时间最小/时间最大值

本文关键字:时间 最大值 事件 Google 日历 API | 更新日期: 2023-09-27 18:30:15

我正在尝试使用Google .Net客户端库来查询Google日历事件。

我成功地拉下了事件,但它似乎完全忽略了 TimeMin 和 TimeMax,并返回该时间范围之外的事件。

作为测试,我用AddDays()将这个窗口从昨天的这个时候扩大到明天的这个时候。

我的代码是:

    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;

今天(11/12/14 ...所以 11/11/14 到 11/13/14 使用上面的代码)这是从 11/5/14 返回的事件。

使用 .Net 库,这两个属性被定义为可为空的 DateTime 对象 ( DateTime? ),因此我不会将这些属性格式化为任何标准。

我在这里做错了什么吗?

编辑:我遇到了以下链接。如果此信息为真,则如何从DateTime?这些字段的 .Net 中处理此问题。

/

events/list 接受 timeMin 和 timeMax 参数,这些参数是 简单地说是接受"日期时间"参数。在无数的 可能的标准化日期时间格式,我发现这 值应为 UTC 日期时间(偏移量显式设置为 00:00) 格式为 RFC3339 (yyyy-MM-ddThh:mm:ss.sss+00:00)。

谷歌日历 API v3 取消文档

C# Google 日历 API 忽略事件时间最小/时间最大值

我能够通过将 SingleEvents 属性设置为 true 来使其工作。

似乎某些超出

日期范围的项目是重复发生的事件。 将"单一事件"设置为 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;