首页 > 解决方案 > CalendarView 只获取今天的事件

问题描述

我正在使用 PHP 中的图表,并为应该只提取今天的事件(包括全天事件)的站点构建日历小部件。

一切正常,但它也会拉动昨天的全天事件,我无法弄清楚我做错了什么。

$today = new DateTime( 'now', new DateTimeZone( 'America/New_York' ) );
$tomorrow = new DateTime( 'tomorrow', new DateTimeZone( 'America/New_York' ) );

$start_date = $today->format('Y-m-d');
$end_date = $tomorrow->format('Y-m-d');

$events = ms_get_data_as_json( 'calendarview?startdatetime=' . $start_date . '&enddatetime=' . $end_date . '&$orderby=start/DateTime' );

格式化的请求字符串输出calendarview?startdatetime=2018-05-18&enddatetime=2018-05-19&$orderby=start/DateTime看起来可以正常工作,但是发送此请求,返回的第一个对象是前一天的全天事件。查看示例输出:

[0] => stdClass Object
(
    [createdDateTime] => 2018-05-18T13:30:37.8672462Z
    [lastModifiedDateTime] => 2018-05-18T13:34:25.2248155Z
    [categories] => Array
        (
        )

    [originalStartTimeZone] => UTC
    [originalEndTimeZone] => UTC
    [reminderMinutesBeforeStart] => 1080
    [isReminderOn] => 
    [hasAttachments] => 
    [subject] => Test yesterday
    [bodyPreview] => 
    [importance] => normal
    [sensitivity] => normal
    [isAllDay] => 1
    [isCancelled] => 
    [isOrganizer] => 1
    [responseRequested] => 1
    [seriesMasterId] => 
    [showAs] => free
    [type] => singleInstance
    [onlineMeetingUrl] => 
    [recurrence] => 
    [responseStatus] => stdClass Object
        (
            [response] => organizer
            [time] => 0001-01-01T00:00:00Z
        )

    [body] => stdClass Object
        (
            [contentType] => html
            [content] => 

        )

    [start] => stdClass Object
        (
            [dateTime] => 2018-05-17T00:00:00.0000000
            [timeZone] => UTC
        )

    [end] => stdClass Object
        (
            [dateTime] => 2018-05-18T00:00:00.0000000
            [timeZone] => UTC
        )

)

起始属性显然是针对前一个日期的。

我试图更改我的查询以包含时间戳startdatetime=2018-05-18T00:00:01Z&enddatetime=2018-05-18T23:59:59Z,但我仍然得到相同的结果。我尝试将我的$today$tomorrow变量更改为使用 UTC,因为返回的结果显示OriginalStartTimeZone为 UTC,但我仍然得到相同的结果。

任何帮助表示赞赏。

标签: phpmicrosoft-graph-api

解决方案


我认为应用开始/结束日期过滤器的方式存在一些不平等问题,它最终包括在开始时间结束(或在结束时间开始)的事件。

目前,似乎解决方案是在过滤器的开始时间上增加 1 秒,从过滤器的结束时间中减去 1 秒。您仍会收到请求日期的全天事件,但不会收到前一天或第二天的全天事件。

如果您发现不适用于此方法的情况,请告诉我们!


推荐阅读