DDay iCal(带非 DST 时区)
我已经在 DDay iCal 库的论坛上发布了内容,但我想将其发布到此处,以防任何用户遇到这种情况。从我的论坛帖子中:
我遇到了 iCal 文件中时区部分生成方式的错误 - 添加不支持夏令时的时区会创建一个空的 VTIMEZONE 部分,这会破坏 iCal 。快速浏览一下代码,我相信该部分是由 TimeZoneInfo.GetAdjustmentRules() 返回的集合生成的,对于不遵守 DST 的时区,该集合为空。
帖子底部的代码应该可以演示这个问题。
如果这不是一个错误(我不相信这是一个错误!),我将非常感谢指导让这些工作发挥作用。
void Main()
{
foreach (var tz in TimeZoneInfo.GetSystemTimeZones())
{
var cal = GetCal(tz);
Console.WriteLine(tz.Id + " :: " + tz.SupportsDaylightSavingTime + " :: " + cal.TimeZones.First().ID);
}
}
iCalendar GetCal(TimeZoneInfo timeZone)
{
var calendar = new iCalendar();
calendar.AddChild(iCalTimeZone.FromSystemTimeZone(timeZone));
var @event = new Event
{
Name = "VEVENT",
DTStart = new iCalDateTime(DateTime.Now, timeZone.Id),
DTEnd = new iCalDateTime(DateTime.Now + TimeSpan.FromHours(1))
};
calendar.Events.Add(@event);
return calendar;
}
I've posted to the forums for the DDay iCal library but thought to post it here in case any users have come across this situation. From my forum post:
I've come across what appears to be a bug in how the time zone section is generated in an iCal file- adding a time zone that does not support Daylight Saving Time creates an empty VTIMEZONE section, which breaks the iCal. A quick glance at the code leads me to believe that the section is generated by the collection returned by TimeZoneInfo.GetAdjustmentRules(), which is empty for time zones that do not observe DST.
The code at the bottom of the post should demonstrate this issue.
If this is not a bug (and I am not convinced that it is!), I'd very much appreciate guidance in getting these to work.
void Main()
{
foreach (var tz in TimeZoneInfo.GetSystemTimeZones())
{
var cal = GetCal(tz);
Console.WriteLine(tz.Id + " :: " + tz.SupportsDaylightSavingTime + " :: " + cal.TimeZones.First().ID);
}
}
iCalendar GetCal(TimeZoneInfo timeZone)
{
var calendar = new iCalendar();
calendar.AddChild(iCalTimeZone.FromSystemTimeZone(timeZone));
var @event = new Event
{
Name = "VEVENT",
DTStart = new iCalDateTime(DateTime.Now, timeZone.Id),
DTEnd = new iCalDateTime(DateTime.Now + TimeSpan.FromHours(1))
};
calendar.Events.Add(@event);
return calendar;
}
我从 SVN 上下载了最新的源代码,并且已经应用了这个问题的修复;它只是不在 2011 年 6 月 30 日的最新版本 DLL 中。
I pulled down the latest source from SVN and the fix for this has already been applied; it's just not in the latest release DLL as of 6/30/2011.