Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deserialize STANDARD and DAYLIGHT timezone infos #420

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 40 additions & 7 deletions net-core/Ical.Net.FrameworkUnitTests/SerializationTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
Expand All @@ -10,6 +10,7 @@
using Ical.Net.Serialization.DataTypes;
using Ical.Net.Utility;
using NUnit.Framework;
using System.IO;

namespace Ical.Net.FrameworkUnitTests
{
Expand Down Expand Up @@ -420,11 +421,11 @@ public void UnicodeDescription()
DTEND;TZID=Europe/Helsinki:20160707T140000
SUMMARY:Some summary
UID:20160627T123608Z-182847102@atlassian.net
DESCRIPTION:Key points:\n Some text (text,
, text\, text\, TP) some text\;\n some tex
t Some text (Text\, Text)\;\n Some tex
DESCRIPTION:Key points:\n Some text (text,
, text\, text\, TP) some text\;\n some tex
t Some text (Text\, Text)\;\n Some tex
t some text\, some text\, text.\;\n\nsome te
xt some text some text.
xt some text some text.
ORGANIZER;X-CONFLUENCE-USER-KEY=ff801df01547101c6720006;CN=Some
user;CUTYPE=INDIVIDUAL:mailto:some.mail@domain.com
CREATED:20160627T123608Z
Expand All @@ -439,8 +440,40 @@ public void UnicodeDescription()
var deserializedEvent = Calendar.Load<CalendarEvent>(ics).Single();

Assert.IsTrue(deserializedEvent.Description.Contains("\t"));
Assert.IsTrue(deserializedEvent.Description.Contains("�"));
Assert.IsTrue(deserializedEvent.Description.Contains("�"));
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]
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 @@ -5,6 +5,7 @@
using Ical.Net.Utility;
using NodaTime;
using NodaTime.TimeZones;
using Ical.Net.Proxies;

namespace Ical.Net.CalendarComponents
{
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