microsoftgraph / microsoftgraph/msgraph-sdk-php

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

Open
#1,347 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

needs investigation
Dominant language
PHP
Stars
669
Forks
150
Avg merge
15h 21m
Merged PRs (30d)
3

Description

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();
}


Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the two Outlook calendar cases with the shown PHP calendarView/delta request and compare the returned start, end, and isAllDay fields. Then determine whether the discrepancy is introduced by the SDK request or by the Microsoft Graph calendar API; completion requires identifying the responsible layer and documenting a verified fix or limitation.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
api
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.