Skip to content

Commit

Permalink
Merge pull request #519 from rianjs/DeserializeVtimezoneInfo
Browse files Browse the repository at this point in the history
deserialize STANDARD and DAYLIGHT timezone infos - closes #420
  • Loading branch information
rianjs authored Apr 10, 2021
2 parents 4112ef9 + a5d100f commit 5358016
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 3 deletions.
32 changes: 32 additions & 0 deletions net-core/Ical.Net.CoreUnitTests/SerializationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,38 @@ xt some tex�t some text.
Assert.IsTrue(deserializedEvent.Description.Contains(""));
Assert.IsTrue(deserializedEvent.Description.Contains(""));
}

[Test]
public void TestStandardDaylightTimeZoneInfoDeserialization()
{

const string ics = @"BEGIN:VTIMEZONE
TZID:
BEGIN:STANDARD
DTSTART:16010101T030000
TZOFFSETFROM:+0200
TZOFFSETTO:+0100
RRULE:FREQ=YEARLY;INTERVAL=1;BYDAY=-1SU;BYMONTH=10
END:STANDARD
BEGIN:DAYLIGHT
DTSTART:16010101T020000
TZOFFSETFROM:+0100
TZOFFSETTO:+0200
RRULE:FREQ=YEARLY;INTERVAL=1;BYDAY=-1SU;BYMONTH=3
END:DAYLIGHT
END:VTIMEZONE";
var timeZone = Calendar.Load<VTimeZone>(ics).Single();
Assert.IsNotNull(timeZone, "Expected the TimeZone to be successfully deserialized");
var timeZoneInfos = timeZone.TimeZoneInfos;
Assert.IsNotNull(timeZoneInfos, "Expected TimeZoneInfos to be deserialized");
Assert.AreEqual(2, timeZoneInfos.Count, "Expected 2 TimeZoneInfos");
Assert.AreEqual("STANDARD", timeZoneInfos[0].Name);
Assert.AreEqual(new UtcOffset("+0200"), timeZoneInfos[0].OffsetFrom);
Assert.AreEqual(new UtcOffset("+0100"), timeZoneInfos[0].OffsetTo);
Assert.AreEqual("DAYLIGHT", timeZoneInfos[1].Name);
Assert.AreEqual(new UtcOffset("+0100"), timeZoneInfos[1].OffsetFrom);
Assert.AreEqual(new UtcOffset("+0200"), timeZoneInfos[1].OffsetTo);
}

[Test]
public void TestRRuleUntilSerialization()
Expand Down
7 changes: 4 additions & 3 deletions net-core/Ical.Net/CalendarComponents/VTimeZone.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using Ical.Net.DataTypes;
using Ical.Net.Proxies;
using Ical.Net.Utility;
using NodaTime;
using NodaTime.TimeZones;
Expand Down Expand Up @@ -151,13 +152,13 @@ private static VTimeZoneInfo CreateTimeZoneInfo(List<ZoneInterval> matchedInterv

if (isDaylight)
{
timeZoneInfo.Name = "DAYLIGHT";
timeZoneInfo.Name = Components.Daylight;
timeZoneInfo.OffsetFrom = new UtcOffset(utcOffset);
timeZoneInfo.OffsetTo = new UtcOffset(utcOffset - delta);
}
else
{
timeZoneInfo.Name = "STANDARD";
timeZoneInfo.Name = Components.Standard;
timeZoneInfo.OffsetFrom = new UtcOffset(utcOffset + delta);
timeZoneInfo.OffsetTo = new UtcOffset(utcOffset);
}
Expand Down Expand Up @@ -341,7 +342,7 @@ public string Location
}
}

public HashSet<VTimeZoneInfo> TimeZoneInfos { get; set; }
public ICalendarObjectList<VTimeZoneInfo> TimeZoneInfos => new CalendarObjectListProxy<VTimeZoneInfo>(Children);

protected bool Equals(VTimeZone other)
=> string.Equals(Name, other.Name, StringComparison.OrdinalIgnoreCase)
Expand Down
4 changes: 4 additions & 0 deletions net-core/Ical.Net/Serialization/CalendarComponentFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ public virtual ICalendarComponent Build(string objectName)
case Components.Calendar:
c = new Calendar();
break;
case Components.Daylight:
case Components.Standard:
c = new VTimeZoneInfo();
break;
default:
c = new CalendarComponent();
break;
Expand Down

0 comments on commit 5358016

Please sign in to comment.