Skip to content
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
1 change: 1 addition & 0 deletions Ical.Net.Benchmarks/ApplicationWorkflows.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Ical.Net.Evaluation;

namespace Ical.Net.Benchmarks;

Expand Down
1 change: 1 addition & 0 deletions Ical.Net.Benchmarks/CalDateTimePerfTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using BenchmarkDotNet.Attributes;
using Ical.Net.DataTypes;
using System;
using Ical.Net.Evaluation;

namespace Ical.Net.Benchmarks;

Expand Down
1 change: 1 addition & 0 deletions Ical.Net.Benchmarks/OccurencePerfTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Ical.Net.Evaluation;

namespace Ical.Net.Benchmarks;

Expand Down
27 changes: 14 additions & 13 deletions Ical.Net.Tests/CalDateTimeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using Ical.Net.Evaluation;

namespace Ical.Net.Tests;

Expand Down Expand Up @@ -55,10 +56,10 @@ public void ToTimeZoneFloating()
[Test, TestCaseSource(nameof(ToTimeZoneTestCases))]
public void ToTimeZoneTests(CalendarEvent calendarEvent, string targetTimeZone)
{
var startAsUtc = calendarEvent.Start.AsUtc;
var startAsUtc = calendarEvent.Start!.AsUtc();

var convertedStart = calendarEvent.Start.ToTimeZone(targetTimeZone);
var convertedAsUtc = convertedStart.AsUtc;
var convertedAsUtc = convertedStart.AsUtc();

Assert.That(convertedAsUtc, Is.EqualTo(startAsUtc));
}
Expand Down Expand Up @@ -96,11 +97,11 @@ public void SameDateTimeWithDifferentTzIdShouldReturnSameUtc()
var someTime = DateTimeOffset.Parse("2018-05-21T11:35:00-04:00", CultureInfo.InvariantCulture);

var someDt = new CalDateTime(someTime.DateTime, "America/New_York");
var firstUtc = someDt.AsUtc;
var firstUtc = someDt.AsUtc();
Assert.That(firstUtc, Is.EqualTo(someTime.UtcDateTime));

someDt = new CalDateTime(someTime.DateTime, "Europe/Berlin");
var berlinUtc = someDt.AsUtc;
var berlinUtc = someDt.AsUtc();
Assert.That(berlinUtc, Is.Not.EqualTo(firstUtc));
}

Expand Down Expand Up @@ -190,15 +191,15 @@ public static IEnumerable DateTimeArithmeticTestCases()

yield return new TestCaseData(new Func<CalDateTime, CalDateTime>(dt => dt.AddHours(1)))
.Returns(dateTime.AddHours(1))
.SetName($"{nameof(CalDateTime.AddHours)} 1 hour");
.SetName($"{nameof(CalDateTimeExtensions.AddHours)} 1 hour");

yield return new TestCaseData(new Func<CalDateTime, CalDateTime>(dt => dt.Add(Duration.FromSeconds(30))))
.Returns(dateTime.Add(TimeSpan.FromSeconds(30)))
.SetName($"{nameof(CalDateTime.Add)} 30 seconds");
.SetName($"{nameof(CalDateTimeExtensions.Add)} 30 seconds");

yield return new TestCaseData(new Func<CalDateTime, CalDateTime>(dt => dt.AddMinutes(70)))
.Returns(dateTime.AddMinutes(70))
.SetName($"{nameof(CalDateTime.AddMinutes)} 70 minutes");
.SetName($"{nameof(CalDateTimeExtensions.AddMinutes)} 70 minutes");
}

[Test, TestCaseSource(nameof(EqualityTestCases))]
Expand Down Expand Up @@ -259,27 +260,27 @@ public static IEnumerable DateOnlyValidArithmeticTestCases()

yield return new TestCaseData(new Func<CalDateTime, CalDateTime>(dt => dt.Add(-Duration.FromDays(1))))
.Returns((dateTime.AddDays(-1), false))
.SetName($"{nameof(CalDateTime.Add)} -1 day TimeSpan");
.SetName($"{nameof(CalDateTimeExtensions.Add)} -1 day TimeSpan");

yield return new TestCaseData(new Func<CalDateTime, CalDateTime>(dt => dt.AddYears(1)))
.Returns((dateTime.AddYears(1), false))
.SetName($"{nameof(CalDateTime.AddYears)} 1 year");
.SetName($"{nameof(CalDateTimeExtensions.AddYears)} 1 year");

yield return new TestCaseData(new Func<CalDateTime, CalDateTime>(dt => dt.AddMonths(2)))
.Returns((dateTime.AddMonths(2), false))
.SetName($"{nameof(CalDateTime.AddMonths)} 2 months");
.SetName($"{nameof(CalDateTimeExtensions.AddMonths)} 2 months");

yield return new TestCaseData(new Func<CalDateTime, CalDateTime>(dt => dt.AddDays(7)))
.Returns((dateTime.AddDays(7), false))
.SetName($"{nameof(CalDateTime.AddDays)} 7 days");
.SetName($"{nameof(CalDateTimeExtensions.AddDays)} 7 days");

yield return new TestCaseData(new Func<CalDateTime, CalDateTime>(dt => dt.Add(Duration.FromDays(1))))
.Returns((dateTime.Add(TimeSpan.FromDays(1)), false))
.SetName($"{nameof(CalDateTime.Add)} 1 day TimeSpan");
.SetName($"{nameof(CalDateTimeExtensions.Add)} 1 day TimeSpan");

yield return new TestCaseData(new Func<CalDateTime, CalDateTime>(dt => dt.Add(Duration.Zero)))
.Returns((dateTime.Add(TimeSpan.Zero), false))
.SetName($"{nameof(CalDateTime.Add)} TimeSpan.Zero");
.SetName($"{nameof(CalDateTimeExtensions.Add)} TimeSpan.Zero");
}

[Test]
Expand Down
1 change: 1 addition & 0 deletions Ical.Net.Tests/PeriodListWrapperTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Linq;
using Ical.Net.CalendarComponents;
using Ical.Net.DataTypes;
using Ical.Net.Evaluation;
using Ical.Net.Serialization;
using NUnit.Framework;

Expand Down
35 changes: 34 additions & 1 deletion Ical.Net.Tests/RecurrenceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3986,7 +3986,7 @@ public void TestDtStartTimezone(string? tzId)
var cal = Calendar.Load(icalText)!;
var evt = cal.Events.First();
var ev = new EventEvaluator(evt);
var occurrences = ev.Evaluate(evt.DtStart!, evt.DtStart!.ToTimeZone(tzId), null).TakeWhileBefore(evt.DtStart.AddMinutes(61).ToTimeZone(tzId));
var occurrences = ev.Evaluate(evt.DtStart!, evt.DtStart!.ToTimeZone(tzId), null).TakeWhileBefore(evt.DtStart!.AddMinutes(61).ToTimeZone(tzId));
var occurrencesStartTimes = occurrences.Select(x => x.StartTime).Take(2).ToList();

var expectedStartTimes = new[]
Expand Down Expand Up @@ -4111,4 +4111,37 @@ public void Disallowed_Recurrence_RangeChecks_Should_Throw()
Assert.That(() => serializer.CheckRange("a", (int?) 0, 1, 2, false), Throws.TypeOf<ArgumentOutOfRangeException>());
});
}

[Test]
public void AmbiguousLocalTime_WithShortDurationOfRecurrence()
{
// Short recurrence falls into an ambiguous local time
// for the end time of the second occurrence because
// of DST transition on 2025-10-25 03:00
// See also: https://github.com/ical-org/ical.net/issues/737
var ics = """
BEGIN:VCALENDAR
BEGIN:VEVENT
DTSTART;TZID=Europe/Vienna:20201024T023000
DURATION:PT45M
RRULE:FREQ=DAILY;UNTIL=20201025T013000Z
END:VEVENT
END:VCALENDAR
""";
var cal = Calendar.Load(ics)!;
var occ = cal.GetOccurrences().ToList();

Assert.Multiple(() =>
{
Assert.That(occ.Count, Is.EqualTo(2));

Assert.That(occ[0].Period.StartTime, Is.EqualTo(new CalDateTime(2020, 10, 24, 2, 30, 0, "Europe/Vienna")));
Assert.That(occ[0].Period.EndTime, Is.EqualTo(new CalDateTime(2020, 10, 24, 3, 15, 0, "Europe/Vienna")));
Assert.That(occ[0].Period.EffectiveDuration, Is.EqualTo(new Duration(0, 0, 0, 45, 0)));

Assert.That(occ[1].Period.StartTime, Is.EqualTo(new CalDateTime(2020, 10, 25, 2, 30, 0, "Europe/Vienna")));
Assert.That(occ[1].Period.EndTime, Is.EqualTo(new CalDateTime(2020, 10, 25, 2, 15, 0, "Europe/Vienna")));
Assert.That(occ[1].Period.EffectiveDuration, Is.EqualTo(new Duration(0, 0, 0, 45, 0)));
});
}
}
1 change: 1 addition & 0 deletions Ical.Net.Tests/RecurrenceWithRDateTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using Ical.Net.CalendarComponents;
using Ical.Net.Collections;
using Ical.Net.DataTypes;
using Ical.Net.Evaluation;
using Ical.Net.Serialization;
using Ical.Net.Utility;
using NUnit.Framework;
Expand Down
1 change: 1 addition & 0 deletions Ical.Net.Tests/SerializationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using System.Text.RegularExpressions;
using Ical.Net.CalendarComponents;
using Ical.Net.DataTypes;
using Ical.Net.Evaluation;
using Ical.Net.Serialization;
using Ical.Net.Serialization.DataTypes;
using Ical.Net.Utility;
Expand Down
1 change: 1 addition & 0 deletions Ical.Net/CalendarComponents/VTimeZone.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Ical.Net.Evaluation;

namespace Ical.Net.CalendarComponents;

Expand Down Expand Up @@ -323,7 +324,7 @@
return;
}

_nodaZone = DateUtil.GetZone(value);

Check warning on line 327 in Ical.Net/CalendarComponents/VTimeZone.cs

View workflow job for this annotation

GitHub Actions / tests

Possible null reference argument for parameter 'tzId' in 'DateTimeZone DateUtil.GetZone(string tzId)'.

Check warning on line 327 in Ical.Net/CalendarComponents/VTimeZone.cs

View workflow job for this annotation

GitHub Actions / coverage

Possible null reference argument for parameter 'tzId' in 'DateTimeZone DateUtil.GetZone(string tzId)'.

Check warning on line 327 in Ical.Net/CalendarComponents/VTimeZone.cs

View workflow job for this annotation

GitHub Actions / coverage

Possible null reference argument for parameter 'tzId' in 'DateTimeZone DateUtil.GetZone(string tzId)'.
var id = _nodaZone.Id;
if (string.IsNullOrWhiteSpace(id))
{
Expand Down
1 change: 1 addition & 0 deletions Ical.Net/CalendarExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System;
using System.Globalization;
using Ical.Net.DataTypes;
using Ical.Net.Evaluation;

namespace Ical.Net;

Expand Down
Loading
Loading