Skip to content

Commit

Permalink
fix 4/5 week dts timing bug
Browse files Browse the repository at this point in the history
Revert "fix 4/5 week dts timing bug"

This reverts commit b7bbc89.

Fix issues with 5 week DST transition months
  • Loading branch information
Erik Knudsen authored and eriknuds committed Aug 22, 2023
1 parent 1ad17e5 commit 8e58ae3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 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
7 changes: 5 additions & 2 deletions src/Ical.Net/CalendarComponents/VTimeZone.cs
Original file line number Diff line number Diff line change
Expand Up @@ -254,9 +254,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

0 comments on commit 8e58ae3

Please sign in to comment.