从daydayical.net迁移到Ical.Net



你好,我是从DDay迁移过来的。ical到ical。Net nuget包,但我被困在下面的代码,其中添加时区在DDay。日历请帮忙

之前代码:

List<DOAppointment> lst = objResponse.Appointments;
string timeZoneName = objResponse.UserTimezone; 
iCalendar calendar = new DDay.iCal.iCalendar();
var timeZone = TimeZoneInfo.FindSystemTimeZoneById(timeZoneName); 
calendar.AddTimeZone(iCalTimeZone.FromSystemTimeZone(timeZone));

迁移到Ical。净:

  List<DOAppointment> lst = objResponse.Appointments;
  string timeZoneName = objResponse.UserTimezone;
  Ical.Net.Calendar calendar = new Ical.Net.Calendar();
  var  timeZone = TimeZoneInfo.FindSystemTimeZoneById(timeZoneName); 
  ITimeZone tzID = timeZone;
  calendar.AddTimeZone(tzID);

我知道那个日历。AddTimezone将采取ITimezone,但如何通过它,我没有得到请帮助。

VTimeZoneITimeZone接口的具体实现。ical.net的示例如下:

var calendar = new Ical.Net.Calendar();
// ical.net supports BCL time zones as well as IANA time zones
calendar.AddTimeZone(new VTimeZone(objResponse.UserTimezone));

将来,我可能会更改VTimeZone构造函数,以便在时区字符串与任何已知内容不匹配时抛出异常。但现在,它还很蠢。在幕后,如果其他所有方法都失败,ical.net将默认使用运行代码的系统时区。这可能不太好。

我还添加了一个wiki页面,改编了您的问题:

https://github.com/rianjs/ical.net/wiki/Working-with-time-zones

最新更新