VCALENDAR .ics文件问题

时间:2014-06-30 18:27:58

标签: c#

我有一个.ics文件,当最终用户注册课程时,它会将日历属性设置为OutLook 2010。我的服务器位于东海岸(或EST区域)。但是,我申请的两个区域是中央标准时区(CST)和山区标准时区(MST)。我的问题是,如果课程startime是CST并且用户从MST区域注册,日历条目设置在Outlook中,则日历条目设置在实际开始时间之前2小时。一个例子是课程从上午10:30开始,我注册了课程,我在MST区。我的Outlook日历条目将课程设置为上午8:30而非上午9:30开始。 此外,如果课程是MST区域而且我也是MST区域,则课程设置在课程开始时间后一小时。在MST开始下课时间的课程示例我注册课程并且我也在MST中Outlook日历条目设置条目在下午3:00时应该是下午2:00 我的代码如下:`

//create the Body in VCALENDAR format
string calDateFormat = "yyyyMMddTHHmmssZ";
string bodyCalendar = "BEGIN:VCALENDAR\r\nMETHOD:REQUEST\r\nPRODID:Microsoft CDO for Microsoft Exchange\r\nVERSION:2.0\r\nBEGIN:VTIMEZONE\r\nX-MICROSOFT-CDO-TZID:11\r\nBEGIN:STANDARD\r\nDTSTART:16010101T020000\r\nTZOFFSETFROM:-0500\r\nTZOFFSETTO:-0600\r\nRRULE:FREQ=YEARLY;WKST=MO;INTERVAL=1;BYMONTH=11;BYDAY=1SU\r\nEND:STANDARD\r\nBEGIN:DAYLIGHT\r\nDTSTART:16010101T020000\r\nTZOFFSETFROM:-0600\r\nTZOFFSETTO:-0500\r\nRRULE:FREQ=YEARLY;WKST=MO;INTERVAL=1;BYMONTH=3;BYDAY=2SU\r\nEND:DAYLIGHT\r\nEND:VTIMEZONE\r\nBEGIN:VEVENT\r\nDTSTAMP:{8}\r\nDTSTART:{0}\r\nSUMMARY:{7}\r\nUID:{5}\r\nATTENDEE;ROLE=REQ-PARTICIPANT;PARTSTAT=NEEDS-ACTION;RSVP=TRUE;CN=\"{9}\":MAILTO:{9}\r\nACTION;RSVP=TRUE;CN=\"{4}\":MAILTO:{4}\r\nORGANIZER;CN=\"{3}\":mailto:{4}\r\nLOCATION:{2}\r\nDTEND:{1}\r\nDESCRIPTION:{7}\\N\r\nSEQUENCE:1\r\nPRIORITY:5\r\nCLASS:\r\nCREATED:{8}\r\nLAST-MODIFIED:{8}\r\nSTATUS:CONFIRMED\r\nTRANSP:OPAQUE\r\nX-MICROSOFT-CDO-BUSYSTATUS:BUSY\r\nX-MICROSOFT-CDO-INSTTYPE:0\r\nX-MICROSOFT-CDO-INTENDEDSTATUS:BUSY\r\nX-MICROSOFT-CDO-ALLDAYEVENT:FALSE\r\nX-MICROSOFT-CDO-IMPORTANCE:1\r\nX-MICROSOFT-CDO-OWNERAPPTID:-1\r\nX-MICROSOFT-CDO-ATTENDEE-CRITICAL-CHANGE:{8}\r\nX-MICROSOFT-CDO-OWNER-CRITICAL-CHANGE:{8}\r\nBEGIN:VALARM\r\nACTION:DISPLAY\r\nDESCRIPTION:REMINDER\r\nTRIGGER;RELATED=START:-PT00H15M00S\r\nEND:VALARM\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n";
bodyCalendar = string.Format(bodyCalendar,
            start.ToUniversalTime().ToString(calDateFormat),
            end.ToUniversalTime().ToString(calDateFormat),
            location,
            organizerName,
            organizerEmail,
            Guid.NewGuid().ToString("B"),
            summary,
            subject,
            DateTime.Now.ToUniversalTime().ToString(calDateFormat),
            attendeeList.ToString());

AlternateView calendarView = AlternateView.CreateAlternateViewFromString(bodyCalendar, calendarType);
calendarView.TransferEncoding = TransferEncoding.SevenBit;
msg.AlternateViews.Add(calendarView);

这是我的代码来抵消东部时区:

if ((state == "CO" || state == "WY" || state == "MT") && classTimeZone == "MST")
{
    StartDate = StartDate + TimeSpan.Parse("2:00");
    EndDate = EndDate + TimeSpan.Parse("2:00");
}
else if ((state == "CO" || state == "WY" || state == "MT") && classTimeZone == "CST")
{
    StartDate = StartDate + TimeSpan.Parse("1:00");
    EndDate = EndDate + TimeSpan.Parse("1:00");
}
else if ((state == "ND" || state == "SD" || state == "KS" || state == "NE" || state == "MO" || state == "IA") && classTimeZone == "MST")
{
    StartDate = StartDate + TimeSpan.Parse("2:00");
    EndDate = EndDate + TimeSpan.Parse("2:00");
}
else if ((state == "ND" || state == "SD" || state == "KS" || state == "NE" || state == "MO" || state == "IA") && classTimeZone == "CST")
{
    StartDate = StartDate + TimeSpan.Parse("1:00");
    EndDate = EndDate + TimeSpan.Parse("1:00");
}

0 个答案:

没有答案