简体   繁体   中英

When creating all-day-events using microsoft graph api the last day is always missing

I am creating a microsoft graph event object using this code:

Event @event = new Event
{
  Subject = subject,
  Body = new ItemBody
  {
    ContentType = BodyType.Html,
    Content = $"<div id=\"BookingId\">{ id }</div><div id=\"CheckSum\">{ checkSum }</div>"
  },
  Start = new DateTimeTimeZone
  {
    DateTime = begin.ToString("yyyy-MM-ddTHH:mm:ss", new CultureInfo("de-AT")),
    TimeZone = TimeZoneInfo.Local.Id
    },
    End = new DateTimeTimeZone
    {
        DateTime = end.ToString("yyyy-MM-ddTHH:mm:ss", new CultureInfo("de-AT")),
        TimeZone = TimeZoneInfo.Local.Id
    },
    Location = new Location
    {
        DisplayName = location
    },
    Attendees = new List<Attendee>(),
    IsAllDay = true
};

TimeZone is set to "W. Europe Standard Time" when this code runs on my machine. Events will be added like this:

await graphClient.Groups[group.Id].Events
   .Request()
   .AddAsync(@event);

This works so far but all my events have one day less than I originally set for the end time. Also tried to add some hours but then I get an exception saying that allDayEvents have to start and end at midnight. But setting them to midnight removes the last day of the event.

The easiest workaround seems to be always adding one day to the end date. But what if this is only a daylight savings problem and I will then get one day to much in winter? I did not find any possibility to add the daylight saving hour to the start and end date.

Additional information: The datetime objects I am using in the code above are already having "00:00:00" as the time. This can also be seen from the text above as there will be an exception when using a different time. Therefore the answer to the linked question did not solve my problem. So, no need to vote down my question.

When creating an "All Day" event, you start and end times should only specify the date, not the date and time (or more accurately, the time should be 00:00:00 ):

Start = new DateTimeTimeZone
{
    DateTime = begin..ToString("yyyy-MM-ddT00:00:00"),
    TimeZone = TimeZoneInfo.Local.Id
},
End = new DateTimeTimeZone
{
    DateTime = end.ToString("yyyy-MM-ddT00:00:00"),
    TimeZone = TimeZoneInfo.Local.Id
},

Very similar to this question: Creating All Day Event failing

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM