Office 365 API为整天事件返回错误的开始和结束日期时间

时间:2016-01-20 21:18:50

标签: json api outlook office365 outlook-restapi

以下是重现错误的步骤:

  1. 检查Office 365中的时区设置,我的设置为美国东部,因此现在是5小时的偏移量:http://take.ms/2qwxJ

  2. 创建全天活动:http://take.ms/tRWSf

  3. 通过在周视图中查看事件并观察其与其他日期不重叠,确认事件在您的时区中的上午12点至中午12点开始和结束。我还确认,通过在与Office 365帐户同步的桌面Outlook客户端中查看它,可以按预期保存整天事件。在那里,您可以看到事件的时区是正确的(EST)。

  4. 通过calendarview api端点查看事件。请注意,它将时区显示为UTC,并将开始和结束时间报告为午夜至午夜UTC。

  5. 获取https://outlook.office.com/api/v1.0/me/calendarview?startDateTime=2016-01-25T01:00:00Z&endDateTime=2016-02-01T23:00:00Z

    {  
      "@odata.context":"https://outlook.office.com/api/v1.0/$metadata#Me/CalendarView",
      "value":[  
        {  
          "@odata.id":"NOT IMPORTANT",
          "@odata.etag":"NOT IMPORTANT",
          "Id":"NOT IMPORTANT",
          "DateTimeCreated":"2016-01-20T20:48:49.3867149Z",
          "DateTimeLastModified":"2016-01-20T20:48:49.4179638Z",
          "ChangeKey":"NOT IMPORTANT",
          "Categories":[  
    
          ],
          "StartTimeZone":"UTC",
          "EndTimeZone":"UTC",
          "ResponseStatus":{  
            "Response":"Organizer",
            "Time":"0001-01-01T00:00:00Z"
          },
          "iCalUId":"NOT IMPORTANT",
          "Reminder":null,
          "HasAttachments":false,
          "Subject":"My all day event, in EST",
          "Body":{  
            "ContentType":"HTML",
            "Content":"<html>\r\n<head>\r\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">\r\n<style type=\"text/css\" style=\"\">\r\n<!--\r\np\r\n\t{margin-top:0;\r\n\tmargin-bottom:0}\r\n-->\r\n</style>\r\n</head>\r\n<body dir=\"ltr\">\r\n<div id=\"divtagdefaultwrapper\" style=\"font-size:12pt; color:#000000; background-color:#FFFFFF; font-family:Calibri,Arial,Helvetica,sans-serif\">\r\n<p><br>\r\n</p>\r\n</div>\r\n</body>\r\n</html>\r\n"
          },
          "BodyPreview":"",
          "Importance":"Normal",
          "Sensitivity":"Normal",
          "Start":"2016-01-26T00:00:00Z",
          "End":"2016-01-27T00:00:00Z",
          "Location":{  
            "DisplayName":""
          },
          "IsAllDay":true,
          "IsCancelled":false,
          "IsOrganizer":true,
          "Recurrence":null,
          "ResponseRequested":true,
          "SeriesMasterId":null,
          "ShowAs":"Busy",
          "Type":"SingleInstance",
          "Attendees":[  
    
          ],
          "Organizer":{  
            "EmailAddress":{  
              "Name":"brett",
              "Address":"NOT IMPORTANT"
            }
          },
          "WebLink":"NOT IMPORTANT"
        }
      ]
    }
    

    我希望东部标准时间的开始和结束时间准确到当天的开始和结束

    "Start":"2016-01-26T05:00:00Z",
    "End":"2016-01-27T05:00:00Z",
    

2 个答案:

答案 0 :(得分:0)

在任何时区,全天活动均为午夜至午夜。 UTC没有任何不同。

答案 1 :(得分:0)

您也可以轻松地从v1 API获取数据, 你只需要确保按时间要求你通过UTC时区并获取信息,你需要指定你期望的时区。

        $date = new DateTime("now", new DateTimeZone('UTC') );
        $deviceTimeStart = $date->format('Y-m-d\TH:i:s\Z');
        $deviceTimeEndPlus1 = $date->modify('+1 minutes');
        $deviceTimeEnd = $deviceTimeEndPlus1->format('Y-m-d\TH:i:s\Z');


            $httpHeader = array(
                "authorization: Bearer *****access_token*****",
                "cache-control: no-cache",
                "Prefer : outlook.timezone = \"Asia/Kolkata\""
            );

            $curl = curl_init();
            curl_setopt_array($curl, array(
                  CURLOPT_URL => 'https://graph.microsoft.com/v1.0/me/calendarview?startDateTime='.$TimeStart.'&endDateTime='.$TimeEnd.'&$select=Subject,Organizer,Start,End,bodyPreview,changeKey,location,attendees,organizer,lastModifiedDateTime',
                  CURLOPT_RETURNTRANSFER => true,
                  CURLOPT_ENCODING => "",
                  CURLOPT_MAXREDIRS => 10,
                  CURLOPT_TIMEOUT => 30,
                  CURLOPT_SSL_VERIFYHOST => 0,
                  CURLOPT_SSL_VERIFYPEER => 0,
                  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
                  CURLOPT_CUSTOMREQUEST => "GET",
                  CURLOPT_HTTPHEADER => $httpHeader,
                )
            );
            $curlResponse = curl_exec($curl);
            $err = curl_error($curl);
            curl_close($curl);
            $responseNew = (array) json_decode($curlResponse, true);