I'm using the graph client sdk. Making a call to CalendarView with startDateTime
= 2019-11-20T10:00:00.0000000
and endDateTime
= 2019-11-20T23:00:00.0000000
.
Before I go any further, none of the Events are all day. Many are reoccurring, so this is why I'm not using the Events endpoint, but using CalendarView.
I have the timezone set for the calendar events by setting prefer, outlook.timezone="Eastern Standard Time"
-- No problem there. I can see the event start and end times in Eastern Standard Time.
However, the events are not correct. I have an event that starts at 8:00 am EST and one that starts at 6:30 pm EST.
The 8:00 am meeting shows--when it should not because my start criteria are 10 am. Not a big deal, but it may be because it ends at 10 am.
The 6:30 pm meeting does NOT show and it should because my end time is 11:00 pm. This is a problem.
If I move the 6:30 meeting up to 6:00 it shows in the collection.
So I'm thinking since I am UTC -5
, the startDateTime
is locked in UTC time. It does not go by the header timezone. I know that the header timezone as mentioned above is working, because the actual start/end of my events will show Eastern if I have the header set, and UTC if I do not.
I can't find anything that allows me to force the calendarview?$select=subject,start, end&startDateTime=2019-11-20T10:00:00.0000000&endDateTime=2019-11-20T23:30:00.0000000
to use my local time.
I played around with this in Graph Explorer and found out that I can put -5
after the time, and it appears to work. I still get the 8:00 am event, but I also get my 6:30 event. I don't want to do this in my code because then I'll be forcing other users to use my timezone.
Does anyone know what setting can be changed to force the CalendarView to use local time for the parameters? I apologize, I'm new to graph client so I may not be using the correct vocabulary.
Code:
GraphServiceClient graphClient = new GraphServiceClient(AuthProvider);
DateTime d = DateTime.Now.ToLocalTime();
DateTime.SpecifyKind(d, DateTimeKind.Unspecified).ToString("o");
string MicrosoftDateTimeFormat = "yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'fffffff";
var start = d.ToString(MicrosoftDateTimeFormat);
var end = d.ToString("yyyy'-'MM'-'dd'T'23:59:59.0"); //"2019-07-24T23:00:00.0";//
start = "2019-11-20T10:00:00.0000000"; //for debug only
end = "2019-11-20T23:00:00.0000000"; //for debug only
List<Option> options = new List<Option>
{
new QueryOption("startDateTime", start),
new QueryOption("endDateTime", end),
new QueryOption("orderby", "start/dateTime")
};
var events = await graphClient.Me.CalendarView
.Request(options)
.Header("Prefer", "outlook.timezone=\"" + TimeZoneInfo.Local.Id + "\"")
.Select(e => new
{
e.Subject,
e.Body,
e.BodyPreview,
e.Organizer,
e.Attendees,
e.Start,
e.End,
e.Location
})
.GetAsync();