msgraph-sdk-php icon indicating copy to clipboard operation
msgraph-sdk-php copied to clipboard

A bug when getting the dateTime for the start and end of an event

Open balaevvit opened this issue 9 months ago • 0 comments

I use this SDK to get user events from the Outlook calendar (https://outlook.office.com/calendar/view/week).

When a user uses a calendar on a website and wants to create an event for the whole day, he can do this in two ways:

  1. Manual - set the time from midnight to midnight.

  2. Use the "All day" checkbox In both cases I set the event for the whole day

The problem is that I get different responses from the API for an event that lasts a day. When creating the event manually I get something like this:

{

    …
	
    "start": {
        "dateTime": "2023-09-17T21:00:00.0000000",
        "timeZone": "UTC"
    },
    "end": {
        "dateTime": "2023-09-18T21:00:00.0000000",
        "timeZone": "UTC"
    },
	
        "isAllDay":false,
	
    …

}

Dates and times were calculated relative to my time zone in Outlook settings.


But when creating an event, check the “All day” checkbox. The response will always be:

{

    …
	
    "start": {
        "dateTime": "2023-09-18T00:00:00.0000000",
        "timeZone": "UTC"
    },
    "end": {
         "dateTime": "2023-09-19T00:00:00.0000000",
         "timeZone": "UTC"
      },
	
    "isAllDay”:true,

     ...
}

The response always contains datetimes from midnight to midnight UTC.


Steps to reproduce:


  1. Use https://outlook.office.com/calendar/view/week

  2. In the settings, set the user's time zone with a UTC offset, for example - (UTC+02:00) Helsinki, Kyiv, Riga, Sofia, Tallinn, Vilnius.

  3. Open a modal window for creating an event (click on an empty space on the calendar).
  4. Select the start and end datetime of the event, for example 2023-09-18 00:00 - for start and 2023-09-19 00:00 to end. Please note that this is a full day event.
  5. Execute a GET request to the calendar API using SDK (my code is shown below)
  6. The response contains the start and end date of the event, which is several hours less than midnight. This is expected behavior. The API calculates datetime relative to the Outlook user's time zone. Remember.

  7. Create a new event on the website, select dates, for example 2023-09-18 and 2023-09-19 but this time click on the “All day” checkbox.

  8. Execute a GET request and get the datetime from midnight to midnight.

  9. Compare the answer in the 1st case and the answer in the 2nd case. Screenshot 2023-09-19 at 12 48 07

Current behavior: For all-day events created manually and events created using the “All day” checkbox, I get a different responses

Expected behavior: Get the same responses from the API when manually selecting a date from midnight to midnight and when selecting the "All day" checkbox.

My code:

$graph = new Graph();
$graph->setAccessToken($accessToken);
$timezone = new \DateTimeZone('UTC');
$start = new \DateTimeImmutable('now', $timezone);
$end = new \DateTimeImmutable('now +1 day +1 hour', $timezone);
$queryParams = [
    'startDateTime' => $start->format(\DateTimeInterface::ATOM),
    'endDateTime' => $end->format(\DateTimeInterface::ATOM),
];
$getEventsUrl = sprintf('/users/%s/calendar/calendarView/delta?%s', $msUserId, http_build_query($queryParams));
$calendarViewIterator = $graph->createCollectionRequest('GET', $getEventsUrl)->setReturnType(Event::class);

$events = [];
while (!$calendarViewIterator->isEnd()) {
    $events[] = $calendarViewIterator->getPage();
}


balaevvit avatar Sep 19 '23 08:09 balaevvit