Search code examples
c#ddayical-dotnet

Is it possible to use UTC Offset instead of timezone name on iCal.net?


My application stores the UTC offset on users profile (-03:00, for instance) and as this page from iCal.net Wiki mentions it seems that I can only use the timezone to assign to the event: https://github.com/rianjs/ical.net/wiki/Working-with-time-zones.

Do I have any other option?


Solution

  • ical.net uses NodaTime under the hood to do time zone conversions, which means you can use the Etc/GMT family of zones. Wikipedia has a nice list. In your case, you would specify a time zone of Etc/GMT-3:

    const string ianaZone = "Etc/GMT-3";
    var start = DateTime.Now;
    var end = start.AddHours(1);
    
    var vEvent = new Event
    {
        DtStart = new CalDateTime(start, ianaZone),
        DtEnd = new CalDateTime(end, ianaZone),
    };