Brett C
Brett C

Reputation: 301

Office 365 API is returning incorrect start and end datetimes for all day events

Here's the steps to reproduce the bug:

  1. Check your timezone settings in Office 365, mine is set to Eastern US, so it's a 5 hour offset right now: http://take.ms/2qwxJ

  2. Create an all-day event: http://take.ms/tRWSf

  3. Confirm that the event starts and ends on 12am - 12am in your timezone by viewing the event in week view and observing that it does not overlap into other days. I have also confirmed they all day event is saved as expected by viewing it in a desktop outlook client that is synced with the office 365 account. There, you can see that the timezone for the event is correct (EST).

  4. view the event via the calendarview api endpoint. Notice that it shows the timezone as UTC, and reports the start and end times as midnight to midnight UTC.

GET 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"
    }
  ]
}

I expect the start and end times to be accurate to the start and end of the day in Eastern Standard Time

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

Upvotes: 4

Views: 1881

Answers (2)

manish1706
manish1706

Reputation: 1599

you can easily fetch data from v1 API too, you just need to insure that on time of asking for time you are passing UTC timezone and for fetching information you need to specify for which timezone you are expecting.

        $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);

Upvotes: 0

Dmitry Streblechenko
Dmitry Streblechenko

Reputation: 66255

All day events are midnight-to-midnight in any time zone. UTC is not any different.

Upvotes: -1

Related Questions