Sending meeting appointment - Wrong time on EN clients

386 Views Asked by At

I'm sending automated meeting invitations based on dates in the a database.I'm using this snippet, to build the invitation file:

private string BuildInvitationFile(MailMessage mail, DateTime fromDate, DateTime toDate)
    {
        StringBuilder str = new StringBuilder();
        str.AppendLine("BEGIN:VCALENDAR");
        str.AppendLine("PRODID:-//Schedule a Meeting");
        str.AppendLine("VERSION:2.0");
        str.AppendLine("METHOD:REQUEST");
        str.AppendLine("BEGIN:VEVENT");

        str.AppendLine(string.Format("DTSTART;VALUE=DATE:{0:yyyyMMdd}", fromDate));
        str.AppendLine(string.Format("DTEND;VALUE=DATE:{0:yyyyMMdd}", toDate.AddDays(1)));

        str.AppendLine("LOCATION: " + "");
        str.AppendLine(string.Format("UID:{0}", Guid.NewGuid()));
        str.AppendLine(string.Format("DESCRIPTION:{0}", mail.Body));
        str.AppendLine(string.Format("X-ALT-DESC;FMTTYPE=text/html:{0}", mail.Body));
        str.AppendLine(string.Format("SUMMARY:{0}", mail.Subject));
        str.AppendLine(string.Format("ORGANIZER:MAILTO:{0}", mail.From.Address));
        str.AppendLine(string.Format("ATTENDEE;CN=\"{0}\";RSVP=TRUE:mailto:{1}", mail.To[0].DisplayName, mail.To[0].Address));
        str.AppendLine("BEGIN:VALARM");
        str.AppendLine("TRIGGER:-PT15M");
        str.AppendLine("ACTION:DISPLAY");
        str.AppendLine("DESCRIPTION:Reminder");
        str.AppendLine("END:VALARM");
        str.AppendLine("END:VEVENT");
        str.AppendLine("END:VCALENDAR");

        return str.ToString();
    }

The problem is, that when this invitation is sent to a recipient having the english version of the Outlook client (we are at Hungary - CET), both DTSTART and DTEND are incremented with 2 hours. Feels a little strange as I'm not using any datetime, only date and these meetings should be "All day" meetings.

1

There are 1 best solutions below

0
On

Assuming iCalendar format. DateTimes should be formatted according to ISO 8601. From what I can tell the following should be valid:

fromDate.ToUniversalTime().ToString("yyyyMMddTHHmmssZ")

producing a time like 20201013T123616Z

The "Z" postfix indicated that the time is in universal time. It will be up to the client to convert it to the local timezone.