Skip to content

Commit

Permalink
fix 4/5 week dts timing bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Erik Knudsen committed Aug 22, 2023
1 parent 1ad17e5 commit b7bbc89
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 12 deletions.
15 changes: 15 additions & 0 deletions src/Ical.Net.CoreUnitTests/VTimeZoneTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,21 @@ public void VTimeZoneAmericaLosAngelesShouldSerializeProperly()
//Assert.IsTrue(serialized.Contains("RDATE:19600424T010000"), "RDATE:19600424T010000 was not serialized"); // NodaTime doesn't match with what tzurl has
}

[Test, Category("VTimeZone")]
public void VTimeZoneEuropeOsloShouldSerializeProperly()
{
var iCal = CreateTestCalendar("Europe/Oslo");
var serializer = new CalendarSerializer();
var serialized = serializer.SerializeToString(iCal);

Assert.IsTrue(serialized.Contains("TZID:Europe/Oslo"), "Time zone not found in serialization");
Assert.IsTrue(serialized.Contains("BEGIN:STANDARD"), "The standard timezone info was not serialized");
Assert.IsTrue(serialized.Contains("BEGIN:DAYLIGHT"), "The daylight timezone info was not serialized");
Assert.IsTrue(serialized.Contains("BYDAY=-1SU;BYMONTH=3"), "BYDAY=-1SU;BYMONTH=3 was not serialized");
Assert.IsTrue(serialized.Contains("BYDAY=-1SU;BYMONTH=10"), "BYDAY=-1SU;BYMONTH=10 was not serialized");

}

[Test, Category("VTimeZone")]
public void VTimeZoneAmericaAnchorageShouldSerializeProperly()
{
Expand Down
16 changes: 8 additions & 8 deletions src/Ical.Net.nuspec
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<id>Ical.Net</id>
<id>Ical.Net.SuperOffice</id>
<version>4.1.11</version>
<title>Ical.Net</title>
<authors>Rian Stockbower, Douglas Day</authors>
<owners>Rian Stockbower</owners>
<title>Ical.Net.SuperOffice</title>
<authors>SuperOffice</authors>
<owners>SuperOffice</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>An iCalendar (RFC 5545) control library for .NET.</description>
<projectUrl>https://github.com/rianjs/ical.net</projectUrl>
<licenseUrl>https://github.com/rianjs/ical.net/blob/master/license.md</licenseUrl>
<releaseNotes>https://github.com/rianjs/ical.net/blob/master/release-notes.md</releaseNotes>
<iconUrl>https://github.com/rianjs/ical.net/raw/master/nuget_logo_150px.png</iconUrl>
<projectUrl>https://github.com/eriknuds/ical.net</projectUrl>
<licenseUrl>https://github.com/eriknuds/ical.net/blob/master/license.md</licenseUrl>
<releaseNotes>https://github.com/eriknuds/ical.net/blob/master/release-notes.md</releaseNotes>
<iconUrl>https://github.com/eriknuds/ical.net/raw/master/nuget_logo_150px.png</iconUrl>
<tags>iCal Calendar icalendar ics outlook events rfc-5545 rfc-2445 dday</tags>
<dependencies>
<dependency id="NodaTime" version="2.0.2" />
Expand Down
9 changes: 7 additions & 2 deletions src/Ical.Net/CalendarComponents/VTimeZone.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Ical.Net.Utility;
using NodaTime;
using NodaTime.TimeZones;
using static System.TimeZoneInfo;

namespace Ical.Net.CalendarComponents
{
Expand Down Expand Up @@ -241,6 +242,7 @@ private static void PopulateTimeZoneInfoRecurrenceDates(VTimeZoneInfo tzi, List<

private static void PopulateTimeZoneInfoRecurrenceRules(VTimeZoneInfo tzi, ZoneInterval interval)
{
//var weekNumber = GetWeekNumber(tzi, interval);
var recurrence = new IntervalRecurrencePattern(interval);
tzi.RecurrenceRules.Add(recurrence);
}
Expand All @@ -254,9 +256,12 @@ public IntervalRecurrencePattern(ZoneInterval interval)

var date = interval.IsoLocalStart.ToDateTimeUnspecified();
var weekday = date.DayOfWeek;
var num = DateUtil.WeekOfMonth(date);
var weekNumber = DateUtil.WeekOfMonth(date);

ByDay.Add(num != 5 ? new WeekDay(weekday, num) : new WeekDay(weekday, -1));
if (weekNumber >= 4)
ByDay.Add(new WeekDay(weekday, -1)); // Almost certainly likely last X-day of month. Avoid issues with 4/5 sundays in different year/months. Ideally, use the nodazone tz database rule for this interval instead.
else
ByDay.Add(new WeekDay(weekday, weekNumber));
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/Ical.Net/Ical.Net.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<PropertyGroup>
<LangVersion>8</LangVersion>
<PackageVersion>4.2.0</PackageVersion>
<Title>Ical.Net</Title>
<Title>Ical.Net.SuperOffice</Title>
<PackageProjectUrl>https://github.com/rianjs/ical.net</PackageProjectUrl>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<RepositoryUrl>https://github.com/rianjs/ical.net</RepositoryUrl>
Expand All @@ -14,7 +14,7 @@
<AssemblyOriginatorKeyFile>..\..\IcalNetStrongnameKey.snk</AssemblyOriginatorKeyFile>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<PackageId>Ical.Net</PackageId>
<PackageId>Ical.Net.SuperOffice</PackageId>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Description>An iCalendar (RFC 5545) library. See https://github.com/rianjs/ical.net for details.</Description>
</PropertyGroup>
Expand Down

0 comments on commit b7bbc89

Please sign in to comment.