Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
130 changes: 77 additions & 53 deletions Ical.Net.Tests/CalendarEventTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -427,34 +427,37 @@ public void EventResourcesCanBeZeroedOut()
public void HourMinuteSecondOffsetParsingTest()
{
const string ical =
@"BEGIN:VCALENDAR
PRODID:-//1&1 Mail & Media GmbH/GMX Kalender Server 3.10.0//NONSGML//DE
VERSION:2.0
CALSCALE:GREGORIAN
METHOD:REQUEST
BEGIN:VTIMEZONE
TZID:Europe/Brussels
TZURL:http://tzurl.org/zoneinfo/Europe/Brussels
X-LIC-LOCATION:Europe/Brussels
BEGIN:DAYLIGHT
TZOFFSETFROM:-001730
TZOFFSETTO:-001730
TZNAME:CEST
DTSTART:19810329T020000
RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=-1SU
END:DAYLIGHT
BEGIN:STANDARD
TZOFFSETFROM:+001730
TZOFFSETTO:+001730
TZNAME:BMT
DTSTART:18800101T000000
RDATE:18800101T000000
END:STANDARD
END:VTIMEZONE
END:VCALENDAR";
"""
BEGIN:VCALENDAR
PRODID:-//1&1 Mail & Media GmbH/GMX Kalender Server 3.10.0//NONSGML//DE
VERSION:2.0
CALSCALE:GREGORIAN
METHOD:REQUEST
BEGIN:VTIMEZONE
TZID:Europe/Brussels
TZURL:http://tzurl.org/zoneinfo/Europe/Brussels
X-LIC-LOCATION:Europe/Brussels
BEGIN:DAYLIGHT
TZOFFSETFROM:-001730
TZOFFSETTO:-001730
TZNAME:CEST
DTSTART:19810329T020000
RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=-1SU
END:DAYLIGHT
BEGIN:STANDARD
TZOFFSETFROM:+001730
TZOFFSETTO:+001730
TZNAME:BMT
DTSTART:18800101T000000
RDATE:18800101T000000
END:STANDARD
END:VTIMEZONE
END:VCALENDAR
""";
var timezones = Calendar.Load(ical)
.TimeZones.First()
.Children.Cast<CalendarComponent>();
.Children.Cast<CalendarComponent>()
.ToArray();

var positiveOffset = timezones
.Skip(1).Take(1).First()
Expand All @@ -472,78 +475,99 @@ public void HourMinuteSecondOffsetParsingTest()


[Test, Category("CalendarEvent")]
public void TestGetEffectiveDuration()
public void GetNominalDurationTests()
{
var now = _now.Subtract(TimeSpan.FromTicks(_now.Ticks % TimeSpan.TicksPerSecond));
var dt = new DateTime(2025, 3, 1, 14, 30, 0);
const string tzIdStart = "America/New_York";
const string tzIdEnd = "Europe/London";

var evt = new CalendarEvent()
var evt = new CalendarEvent
{
DtStart = new CalDateTime(DateOnly.FromDateTime(now), TimeOnly.FromDateTime(now)),
DtEnd = new CalDateTime(DateOnly.FromDateTime(now.AddHours(1)), TimeOnly.FromDateTime(now.AddHours(1)))
DtStart = new CalDateTime(DateOnly.FromDateTime(dt), TimeOnly.FromDateTime(dt), tzIdStart),
DtEnd = new CalDateTime(DateOnly.FromDateTime(dt.AddHours(1)), TimeOnly.FromDateTime(dt.AddHours(1)), tzIdEnd)
};

Assert.Multiple(() =>
{
Assert.That(evt.DtStart.Value, Is.EqualTo(now));
Assert.That(evt.DtEnd.Value, Is.EqualTo(now.AddHours(1)));
Assert.That(evt.GetFirstDuration(), Is.EqualTo(TimeSpan.FromHours(1)));
Assert.That(evt.DtStart.Value, Is.EqualTo(dt));
Assert.That(evt.DtEnd.Value, Is.EqualTo(dt.AddHours(1)));
Assert.That(evt.CalcFirstNominalDuration(), Is.EqualTo(TimeSpan.FromHours(1)));
});

evt = new CalendarEvent()
evt = new CalendarEvent
{
DtStart = new CalDateTime(DateOnly.FromDateTime(now.Date), TimeOnly.FromDateTime(now.Date)),
DtEnd = new CalDateTime(DateOnly.FromDateTime(now.Date.AddHours(1)), TimeOnly.FromDateTime(now.Date.AddHours(1)))
DtStart = new CalDateTime(DateOnly.FromDateTime(dt.Date)),
DtEnd = new CalDateTime(DateOnly.FromDateTime(dt.Date))
};

Assert.Multiple(() =>
{
Assert.That(evt.DtStart.Value, Is.EqualTo(now.Date));
Assert.That(evt.GetFirstDuration(), Is.EqualTo(TimeSpan.FromHours(1)));
Assert.That(evt.DtStart.Value, Is.EqualTo(dt.Date));
Assert.That(evt.CalcFirstNominalDuration(), Is.EqualTo(TimeSpan.Zero));
});

evt = new CalendarEvent()
evt = new CalendarEvent
{
DtStart = new CalDateTime(DateOnly.FromDateTime(now)),
DtStart = new CalDateTime(DateOnly.FromDateTime(dt)),
};

Assert.Multiple(() =>
{
Assert.That(evt.DtStart.Value, Is.EqualTo(now.Date));
Assert.That(evt.GetFirstDuration(), Is.EqualTo(TimeSpan.FromDays(1)));
Assert.That(evt.DtStart.Value, Is.EqualTo(dt.Date));
Assert.That(evt.Duration, Is.Null);
Assert.That(evt.CalcFirstNominalDuration(), Is.EqualTo(TimeSpan.FromDays(1)));
});

evt = new CalendarEvent()
evt = new CalendarEvent
{
DtStart = new CalDateTime(DateOnly.FromDateTime(now), TimeOnly.FromDateTime(now)),
DtStart = new CalDateTime(DateOnly.FromDateTime(dt), TimeOnly.FromDateTime(dt)),
Duration = TimeSpan.FromHours(2),
};

Assert.Multiple(() => {
Assert.That(evt.DtStart.Value, Is.EqualTo(now));
Assert.That(evt.DtStart.Value, Is.EqualTo(dt));
Assert.That(evt.DtEnd, Is.Null);
Assert.That(evt.GetFirstDuration(), Is.EqualTo(TimeSpan.FromHours(2)));
Assert.That(evt.CalcFirstNominalDuration(), Is.EqualTo(TimeSpan.FromHours(2)));
});

evt = new CalendarEvent()
{
DtStart = new CalDateTime(DateOnly.FromDateTime(now.Date), TimeOnly.FromDateTime(now.Date)),
DtStart = new CalDateTime(DateOnly.FromDateTime(dt.Date), TimeOnly.FromDateTime(dt.Date)),
Duration = TimeSpan.FromHours(2),
};

Assert.Multiple(() => {
Assert.That(evt.DtStart.Value, Is.EqualTo(now.Date));
Assert.That(evt.GetFirstDuration(), Is.EqualTo(TimeSpan.FromHours(2)));
Assert.That(evt.DtStart.Value, Is.EqualTo(dt.Date));
Assert.That(evt.CalcFirstNominalDuration(), Is.EqualTo(TimeSpan.FromHours(2)));
});

evt = new CalendarEvent()
{
DtStart = new CalDateTime(DateOnly.FromDateTime(now)),
DtStart = new CalDateTime(DateOnly.FromDateTime(dt)),
Duration = TimeSpan.FromDays(1),
};

Assert.Multiple(() => {
Assert.That(evt.DtStart.Value, Is.EqualTo(now.Date));
Assert.That(evt.GetFirstDuration(), Is.EqualTo(TimeSpan.FromDays(1)));
Assert.That(evt.DtStart.Value, Is.EqualTo(dt.Date));
Assert.That(evt.CalcFirstNominalDuration(), Is.EqualTo(TimeSpan.FromDays(1)));
});
}

[Test]
public void EitherEndTime_OrDuraction_CanBeSet()
{
var evt = new CalendarEvent()
{
DtStart = new CalDateTime(2025, 10, 11, 12, 13, 14, CalDateTime.UtcTzId)
};

Assert.Multiple(() =>
{
Assert.That(() => evt.DtEnd = new CalDateTime(2025, 12, 11), Throws.Nothing);
Assert.That(() => evt.Duration = TimeSpan.FromDays(1), Throws.InvalidOperationException);
Assert.That(() => evt.DtEnd = null, Throws.Nothing);
Assert.That(() => evt.Duration = TimeSpan.FromDays(1), Throws.Nothing);
Assert.That(() => evt.DtEnd = new CalDateTime(2025, 12, 11), Throws.InvalidOperationException);
});
}
}
1 change: 0 additions & 1 deletion Ical.Net.Tests/CollectionHelpersTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ public void ExDateTests()
{
Assert.Multiple(() =>
{
Assert.That(GetExceptionDates(), Is.EqualTo(GetExceptionDates()));
Assert.That(GetExceptionDates(), Is.Not.Null);
Assert.That(GetExceptionDates(), Is.Not.EqualTo(null));
});
Expand Down
3 changes: 1 addition & 2 deletions Ical.Net.Tests/CopyComponentTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ public static IEnumerable CopyCalendarTest_TestCases()
{
DtStart = new CalDateTime(_now),
DtEnd = new CalDateTime(_later),
Duration = TimeSpan.FromHours(1),
};

private static string SerializeEvent(CalendarEvent e) => new CalendarSerializer().SerializeToString(new Calendar { Events = { e } });
Expand Down Expand Up @@ -199,4 +198,4 @@ public void CopyJournalTest()
Assert.That(copy.Status, Is.EqualTo(orig.Status));
});
}
}
}
5 changes: 1 addition & 4 deletions Ical.Net.Tests/EqualityAndHashingTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ public void Event_Tests(CalendarEvent incoming, CalendarEvent expected)
{
DtStart = new CalDateTime(_nowTime),
DtEnd = new CalDateTime(_later),
Duration = TimeSpan.FromHours(1),
};

private static string SerializeEvent(CalendarEvent e) => new CalendarSerializer().SerializeToString(new Calendar { Events = { e } });
Expand Down Expand Up @@ -112,7 +111,6 @@ public void Calendar_Tests()
var e = new CalendarEvent
{
DtStart = new CalDateTime(_nowTime),
DtEnd = new CalDateTime(_later),
Duration = TimeSpan.FromHours(1),
RecurrenceRules = new List<RecurrencePattern> { rruleA },
};
Expand All @@ -130,7 +128,6 @@ public void Calendar_Tests()
expectedCalendar.Events.Add(new CalendarEvent
{
DtStart = new CalDateTime(_nowTime),
DtEnd = new CalDateTime(_later),
Duration = TimeSpan.FromHours(1),
RecurrenceRules = new List<RecurrencePattern> { rruleB },
});
Expand Down Expand Up @@ -501,4 +498,4 @@ public void CalDateTimeComparisonOperatorTests()
TestComparison((dt1, dt2) => dt1 < dt2, (i1, i2) => i1 < i2);
TestComparison((dt1, dt2) => dt1 <= dt2, (i1, i2) => i1 <= i2);
}
}
}
Loading
Loading