diff --git a/Ical.Net.Tests/RecurrenceTests.cs b/Ical.Net.Tests/RecurrenceTests.cs index 273933a81..5998026f2 100644 --- a/Ical.Net.Tests/RecurrenceTests.cs +++ b/Ical.Net.Tests/RecurrenceTests.cs @@ -9,6 +9,7 @@ using System.Globalization; using System.IO; using System.Linq; +using System.Reflection; using System.Text.RegularExpressions; using Ical.Net.CalendarComponents; using Ical.Net.DataTypes; @@ -3317,19 +3318,19 @@ public void AddExDateToEventAfterGetOccurrencesShouldRecomputeResult() Assert.That(occurrences, Has.Count.EqualTo(5)); var exDate = _now.AddDays(1); - e.ExceptionDates.Add(new CalDateTime(exDate, false)); + e.ExceptionDates.Add(exDate); occurrences = e.GetOccurrences(searchStart, searchEnd).ToList(); Assert.That(occurrences, Has.Count.EqualTo(4)); //Specifying just a date should "black out" that date - var excludeTwoDaysFromNow = _now.AddDays(2).Date; - e.ExceptionDates.Add(new CalDateTime(excludeTwoDaysFromNow, false)); + var excludeTwoDaysFromNow = new CalDateTime(_now.Date).AddDays(2); + e.ExceptionDates.Add(excludeTwoDaysFromNow); occurrences = e.GetOccurrences(searchStart, searchEnd).ToList(); Assert.That(occurrences, Has.Count.EqualTo(3)); } - private static readonly DateTime _now = DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Unspecified); - private static readonly DateTime _later = _now.AddHours(1); + private static readonly CalDateTime _now = CalDateTime.Now; + private static readonly CalDateTime _later = _now.AddHours(1); private static CalendarEvent GetEventWithRecurrenceRules() { var dailyForFiveDays = new RecurrencePattern(FrequencyType.Daily, 1) @@ -3381,18 +3382,18 @@ public void ExDateTimeZone_Tests() var e = new CalendarEvent { - DtStart = new CalDateTime(_now, tzid), - DtEnd = new CalDateTime(_later, tzid), + DtStart = new CalDateTime(_now.Date, _now.Time, tzid), + DtEnd = new CalDateTime(_later.Date, _later.Time, tzid), RecurrenceRules = new List { rrule }, }; - e.ExceptionDates.Add(new CalDateTime(_now.AddDays(1), tzid)); + e.ExceptionDates.Add(new CalDateTime(_now.Date, _now.Time, tzid).AddDays(1)); var serialized = SerializationHelpers.SerializeToString(e); const string expected = "TZID=Europe/Stockholm"; Assert.That(Regex.Matches(serialized, expected), Has.Count.EqualTo(3)); - e.ExceptionDates.Add(new CalDateTime(_now.AddDays(2), tzid)); + e.ExceptionDates.Add(new CalDateTime(_now.Date, _now.Time, tzid).AddDays(2)); serialized = SerializationHelpers.SerializeToString(e); Assert.That(Regex.Matches(serialized, expected), Has.Count.EqualTo(3)); } @@ -3458,8 +3459,8 @@ private static CalendarEvent GetSimpleEvent() { var e = new CalendarEvent { - DtStart = new CalDateTime(_now, _tzid), - DtEnd = new CalDateTime(_later, _tzid), + DtStart = new CalDateTime(_now.Date, _now.Time, _tzid), + DtEnd = new CalDateTime(_later.Date, _later.Time, _tzid), }; return e; } diff --git a/Ical.Net.Tests/SerializationTests.cs b/Ical.Net.Tests/SerializationTests.cs index 3dae7c133..9b4c0975f 100644 --- a/Ical.Net.Tests/SerializationTests.cs +++ b/Ical.Net.Tests/SerializationTests.cs @@ -22,13 +22,13 @@ namespace Ical.Net.Tests; [TestFixture] public class SerializationTests { - private static readonly DateTime _nowTime = DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Unspecified); - private static readonly DateTime _later = _nowTime.AddHours(1); + private static readonly CalDateTime _nowTime = CalDateTime.Now; + private static readonly CalDateTime _later = _nowTime.AddHours(1); private static CalendarSerializer GetNewSerializer() => new CalendarSerializer(); private static string SerializeToString(Calendar c) => GetNewSerializer().SerializeToString(c); private static string SerializeToString(CalendarEvent e) => SerializeToString(new Calendar { Events = { e } }); - private static CalendarEvent GetSimpleEvent() => new CalendarEvent { DtStart = new CalDateTime(_nowTime), Duration = (_later - _nowTime).ToDurationExact() }; - private static Calendar UnserializeCalendar(string s) => Calendar.Load(s); + private static CalendarEvent GetSimpleEvent() => new CalendarEvent { DtStart = new CalDateTime(_nowTime), Duration = (_later.Value - _nowTime.Value).ToDurationExact() }; + private static Calendar DeserializeCalendar(string s) => Calendar.Load(s); internal static void CompareCalendars(Calendar cal1, Calendar cal2) { @@ -382,7 +382,7 @@ public void EventStatusAllCaps() var serialized = SerializeToString(e); Assert.That(serialized.Contains(EventStatus.Confirmed, EventStatus.Comparison), Is.True); - var calendar = UnserializeCalendar(serialized); + var calendar = DeserializeCalendar(serialized); var eventStatus = calendar.Events.First().Status; Assert.That(string.Equals(EventStatus.Confirmed, eventStatus, EventStatus.Comparison), Is.True); } @@ -399,7 +399,7 @@ public void ToDoStatusAllCaps() var serialized = SerializeToString(c); Assert.That(serialized.Contains(TodoStatus.NeedsAction, TodoStatus.Comparison), Is.True); - var calendar = UnserializeCalendar(serialized); + var calendar = DeserializeCalendar(serialized); var status = calendar.Todos.First().Status; Assert.That(string.Equals(TodoStatus.NeedsAction, status, TodoStatus.Comparison), Is.True); } @@ -416,7 +416,7 @@ public void JournalStatusAllCaps() var serialized = SerializeToString(c); Assert.That(serialized.Contains(JournalStatus.Final, JournalStatus.Comparison), Is.True); - var calendar = UnserializeCalendar(serialized); + var calendar = DeserializeCalendar(serialized); var status = calendar.Journals.First().Status; Assert.That(string.Equals(JournalStatus.Final, status, JournalStatus.Comparison), Is.True); } @@ -507,8 +507,8 @@ public void TestRRuleUntilSerialization() const string someTz = "Europe/Volgograd"; var e = new CalendarEvent { - Start = new CalDateTime(_nowTime, someTz), - End = new CalDateTime(_nowTime.AddHours(1), someTz), + Start = _nowTime.ToTimeZone(someTz), + End = _nowTime.AddHours(1).ToTimeZone(someTz), RecurrenceRules = new List { rrule }, }; var c = new Calendar diff --git a/Ical.Net/CalendarExtensions.cs b/Ical.Net/CalendarExtensions.cs index 8b0007f47..1da2c3ae1 100644 --- a/Ical.Net/CalendarExtensions.cs +++ b/Ical.Net/CalendarExtensions.cs @@ -5,6 +5,7 @@ using System; using System.Globalization; +using Ical.Net.DataTypes; namespace Ical.Net; @@ -13,7 +14,7 @@ public static class CalendarExtensions /// /// Calculate the week number according to ISO.8601, as required by RFC 5545. /// - public static int GetIso8601WeekOfYear(this System.Globalization.Calendar calendar, DateTime time, DayOfWeek firstDayOfWeek) + public static int GetIso8601WeekOfYear(this System.Globalization.Calendar calendar, CalDateTime time, DayOfWeek firstDayOfWeek) { // A week is defined as a // seven day period, starting on the day of the week defined to be @@ -24,7 +25,7 @@ public static int GetIso8601WeekOfYear(this System.Globalization.Calendar calend // We add 3 to make sure the test date is in the 'right' year, because // otherwise we might end up with week 53 in a year that only has 52. var tTest = GetStartOfWeek(time, firstDayOfWeek).AddDays(3); - var res = calendar.GetWeekOfYear(tTest, CalendarWeekRule.FirstFourDayWeek, firstDayOfWeek); + var res = calendar.GetWeekOfYear(tTest.Value, CalendarWeekRule.FirstFourDayWeek, firstDayOfWeek); return res; } @@ -33,7 +34,7 @@ public static int GetIso8601WeekOfYear(this System.Globalization.Calendar calend /// Calculate and return the date that represents the first day of the week the given date is /// in, according to the week numbering required by RFC 5545. /// - private static DateTime GetStartOfWeek(this DateTime t, DayOfWeek firstDayOfWeek) + private static CalDateTime GetStartOfWeek(this CalDateTime t, DayOfWeek firstDayOfWeek) { var t0 = ((int) firstDayOfWeek) % 7; var tn = ((int) t.DayOfWeek) % 7; @@ -49,7 +50,7 @@ private static DateTime GetStartOfWeek(this DateTime t, DayOfWeek firstDayOfWeek /// E.g. for `2019-12-31` with first day of the week being Monday, the method will return 2020, /// because the week that contains `2019-12-31` is the first week of 2020. /// - public static int GetIso8601YearOfWeek(this System.Globalization.Calendar calendar, DateTime time, DayOfWeek firstDayOfWeek) + public static int GetIso8601YearOfWeek(this System.Globalization.Calendar calendar, CalDateTime time, DayOfWeek firstDayOfWeek) { var year = time.Year; if ((time.Month >= 12) && (calendar.GetIso8601WeekOfYear(time, firstDayOfWeek) == 1)) @@ -66,7 +67,7 @@ public static int GetIso8601YearOfWeek(this System.Globalization.Calendar calend public static int GetIso8601WeeksInYear(this System.Globalization.Calendar calendar, int year, DayOfWeek firstDayOfWeek) { // The last week of the year is the week that contains the 4th-last day of the year (which is the 28th of December in Gregorian Calendar). - var testTime = new DateTime(year + 1, 1, 1, 0, 0, 0, DateTimeKind.Unspecified).AddDays(-4); + var testTime = new CalDateTime(year + 1, 1, 1, 0, 0, 0, null).AddDays(-4); return calendar.GetIso8601WeekOfYear(testTime, firstDayOfWeek); } } diff --git a/Ical.Net/Evaluation/Evaluator.cs b/Ical.Net/Evaluation/Evaluator.cs index d8850ccc6..e07f04f9c 100644 --- a/Ical.Net/Evaluation/Evaluator.cs +++ b/Ical.Net/Evaluation/Evaluator.cs @@ -19,7 +19,7 @@ protected Evaluator() Calendar = CultureInfo.CurrentCulture.Calendar; } - protected void IncrementDate(ref DateTime dt, RecurrencePattern pattern, int interval) + protected void IncrementDate(ref CalDateTime dt, RecurrencePattern pattern, int interval) { if (interval == 0) return; diff --git a/Ical.Net/Evaluation/RecurrencePatternEvaluator.cs b/Ical.Net/Evaluation/RecurrencePatternEvaluator.cs index 95ca9932a..215993912 100644 --- a/Ical.Net/Evaluation/RecurrencePatternEvaluator.cs +++ b/Ical.Net/Evaluation/RecurrencePatternEvaluator.cs @@ -102,20 +102,20 @@ private RecurrencePattern ProcessRecurrencePattern(CalDateTime referenceDate) /// For example, if the search start date (start) is Wed, Mar 23, 12:19PM, but the recurrence is Mon - Fri, 9:00AM - 5:00PM, /// the start dates returned should all be at 9:00AM, and not 12:19PM. /// - private IEnumerable GetDates(CalDateTime seed, CalDateTime? periodStart, CalDateTime? periodEnd, int maxCount, RecurrencePattern pattern, + private IEnumerable GetDates(CalDateTime seed, CalDateTime? periodStart, CalDateTime? periodEnd, int maxCount, RecurrencePattern pattern, bool includeReferenceDateInResults) { // In the first step, we work with DateTime values, so we need to convert the CalDateTime to DateTime - var originalDate = seed.Value; - var seedCopy = seed.Value; - var periodStartDt = periodStart?.ToTimeZone(seed.TzId)?.Value; - var periodEndDt = periodEnd?.ToTimeZone(seed.TzId)?.Value; + var originalDate = seed; + var seedCopy = seed; + var periodStartDt = periodStart?.ToTimeZone(seed.TzId); + var periodEndDt = periodEnd?.ToTimeZone(seed.TzId); if ((pattern.Frequency == FrequencyType.Yearly) && (pattern.ByWeekNo.Count != 0)) { // Dates in the first or last week of the year could belong weeks that belong to // the prev/next year, in which case we must adjust that year. This is necessary - // to get the invervals right. + // to get the intervals right. IncrementDate(ref seedCopy, pattern, Calendar.GetIso8601YearOfWeek(seedCopy, pattern.FirstDayOfWeek) - seedCopy.Year); } @@ -141,7 +141,7 @@ private IEnumerable GetDates(CalDateTime seed, CalDateTime? periodStar return EnumerateDates(originalDate, seedCopy, periodStartDt, periodEndDt, maxCount, pattern); } - private IEnumerable EnumerateDates(DateTime originalDate, DateTime intervalRefTime, DateTime? periodStart, DateTime? periodEnd, int maxCount, RecurrencePattern pattern) + private IEnumerable EnumerateDates(CalDateTime originalDate, CalDateTime intervalRefTime, CalDateTime? periodStart, CalDateTime? periodEnd, int maxCount, RecurrencePattern pattern) { var expandBehavior = RecurrenceUtil.GetExpandBehaviorList(pattern); @@ -150,9 +150,10 @@ private IEnumerable EnumerateDates(DateTime originalDate, DateTime int // As a safe heuristic we add 1d to the UNTIL value to cover any time shift and DST changes. // It's just important that we don't miss any recurrences, not that we stop exactly at UNTIL. // Precise UNTIL handling is done outside this method after TZ conversion. - var coarseUntil = pattern.Until?.Value.AddDays(1); + var coarseUntil = pattern.Until?.AddDays(1); var noCandidateIncrementCount = 0; + var dateCount = 0; while (maxCount < 0 || dateCount < maxCount) { @@ -234,11 +235,11 @@ private struct ExpandContext /// /// /// A list of possible dates. - private ISet GetCandidates(DateTime date, RecurrencePattern pattern, bool?[] expandBehaviors) + private ISet GetCandidates(CalDateTime date, RecurrencePattern pattern, bool?[] expandBehaviors) { var expandContext = new ExpandContext() { DatesFullyExpanded = false }; - var dates = new List { date }; + var dates = new List { date }; dates = GetMonthVariants(dates, pattern, expandBehaviors[0]); dates = GetWeekNoVariants(dates, pattern, expandBehaviors[1], ref expandContext); dates = GetYearDayVariants(dates, pattern, expandBehaviors[2], ref expandContext); @@ -248,7 +249,7 @@ private ISet GetCandidates(DateTime date, RecurrencePattern pattern, b dates = GetMinuteVariants(dates, pattern, expandBehaviors[6]); dates = GetSecondVariants(dates, pattern, expandBehaviors[7]); dates = ApplySetPosRules(dates, pattern); - return new SortedSet(dates); + return new SortedSet(dates); } /// @@ -257,7 +258,7 @@ private ISet GetCandidates(DateTime date, RecurrencePattern pattern, b /// /// The list of dates to which the BYSETPOS rules will be applied. /// - private List ApplySetPosRules(List dates, RecurrencePattern pattern) + private List ApplySetPosRules(List dates, RecurrencePattern pattern) { // return if no SETPOS rules specified.. if (pattern.BySetPosition.Count == 0) @@ -286,7 +287,7 @@ private List ApplySetPosRules(List dates, RecurrencePattern /// /// /// The modified list of dates after applying the BYMONTH rules. - private List GetMonthVariants(List dates, RecurrencePattern pattern, bool? expand) + private List GetMonthVariants(List dates, RecurrencePattern pattern, bool? expand) { if (expand == null || pattern.ByMonth.Count == 0) { @@ -302,7 +303,7 @@ private List GetMonthVariants(List dates, RecurrencePattern } // Limit behavior - var dateSet = new HashSet(dates); + var dateSet = new HashSet(dates); dateSet.ExceptWith(dates.Where(date => pattern.ByMonth.All(t => t != date.Month))); return dateSet.ToList(); } @@ -313,7 +314,7 @@ private List GetMonthVariants(List dates, RecurrencePattern /// /// The list of dates to which the BYWEEKNO rules will be applied. /// The modified list of dates after applying the BYWEEKNO rules. - private List GetWeekNoVariants(List dates, RecurrencePattern pattern, bool? expand, ref ExpandContext expandContext) + private List GetWeekNoVariants(List dates, RecurrencePattern pattern, bool? expand, ref ExpandContext expandContext) { if (expand == null || pattern.ByWeekNo.Count == 0) { @@ -322,11 +323,11 @@ private List GetWeekNoVariants(List dates, RecurrencePattern if (!expand.Value) { - return new List(); + return new List(); } // Expand behavior - var weekNoDates = new List(); + var weekNoDates = new List(); foreach ((var t, var weekNo) in dates.SelectMany(t => GetByWeekNoForYearNormalized(pattern, t.Year), (t, weekNo) => (t, weekNo))) { var date = t; @@ -365,7 +366,7 @@ private List GetWeekNoVariants(List dates, RecurrencePattern return weekNoDates; } - private static DateTime GetFirstDayOfWeekDate(DateTime date, DayOfWeek firstDayOfWeek) + private static CalDateTime GetFirstDayOfWeekDate(CalDateTime date, DayOfWeek firstDayOfWeek) => date.AddDays(-((int) date.DayOfWeek + 7 - (int) firstDayOfWeek) % 7); /// @@ -385,7 +386,7 @@ private List GetByWeekNoForYearNormalized(RecurrencePattern pattern, int ye /// /// The list of dates to which the BYYEARDAY rules will be applied. /// The modified list of dates after applying the BYYEARDAY rules. - private static List GetYearDayVariants(List dates, RecurrencePattern pattern, bool? expand, ref ExpandContext expandContext) + private static List GetYearDayVariants(List dates, RecurrencePattern pattern, bool? expand, ref ExpandContext expandContext) { if (expand == null || pattern.ByYearDay.Count == 0) { @@ -394,7 +395,7 @@ private static List GetYearDayVariants(List dates, Recurrenc if (expand.Value && !expandContext.DatesFullyExpanded) { - var yearDayDates = new List(dates.Count); + var yearDayDates = new List(dates.Count); foreach (var date in dates) { var date1 = date; @@ -443,7 +444,7 @@ private static List GetYearDayVariants(List dates, Recurrenc /// /// The list of dates to which the BYMONTHDAY rules will be applied. /// The modified list of dates after applying the BYMONTHDAY rules. - private List GetMonthDayVariants(List dates, RecurrencePattern pattern, bool? expand, ref ExpandContext expandContext) + private List GetMonthDayVariants(List dates, RecurrencePattern pattern, bool? expand, ref ExpandContext expandContext) { if (expand == null || pattern.ByMonthDay.Count == 0) { @@ -452,7 +453,7 @@ private List GetMonthDayVariants(List dates, RecurrencePatte if (expand.Value && !expandContext.DatesFullyExpanded) { - var monthDayDates = new List(); + var monthDayDates = new List(); foreach (var date in dates) { monthDayDates.AddRange( @@ -511,7 +512,7 @@ select monthDay > 0 /// /// The list of dates to which BYDAY rules will be applied. /// The modified list of dates after applying BYDAY rules, or the original list if no BYDAY rules are specified. - private List GetDayVariants(List dates, RecurrencePattern pattern, bool? expand, ref ExpandContext expandContext) + private List GetDayVariants(List dates, RecurrencePattern pattern, bool? expand, ref ExpandContext expandContext) { if (expand == null || pattern.ByDay.Count == 0) { @@ -521,7 +522,7 @@ private List GetDayVariants(List dates, RecurrencePattern pa if (expand.Value && !expandContext.DatesFullyExpanded) { // Expand behavior - var weekDayDates = new List(); + var weekDayDates = new List(); foreach (var date in dates) { foreach (var day in pattern.ByDay) @@ -570,9 +571,9 @@ private List GetDayVariants(List dates, RecurrencePattern pa /// The date to start the evaluation from. /// The week day to evaluate. /// A list of applicable dates. - private List GetAbsWeekDays(DateTime date, WeekDay weekDay, RecurrencePattern pattern) + private List GetAbsWeekDays(CalDateTime date, WeekDay weekDay, RecurrencePattern pattern) { - var days = new List(); + var days = new List(); var dayOfWeek = weekDay.DayOfWeek; if (pattern.Frequency == FrequencyType.Daily) @@ -661,7 +662,7 @@ private List GetAbsWeekDays(DateTime date, WeekDay weekDay, Recurrence /// /// Returns the days since the start of the week, 0 if the date is on the first day of the week. /// - private static int GetWeekDayOffset(DateTime date, DayOfWeek startOfWeek) + private static int GetWeekDayOffset(CalDateTime date, DayOfWeek startOfWeek) => date.DayOfWeek + ((date.DayOfWeek < startOfWeek) ? 7 : 0) - startOfWeek; /// @@ -671,14 +672,14 @@ private static int GetWeekDayOffset(DateTime date, DayOfWeek startOfWeek) /// /// The list from which to extract the element. /// The position of the element to extract. - private List GetOffsetDates(List dates, int? offset) + private List GetOffsetDates(List dates, int? offset) { if (offset is null) { return dates; } - var offsetDates = new List(); + var offsetDates = new List(); var size = dates.Count; if (offset < 0 && offset >= -size) { @@ -699,7 +700,7 @@ private List GetOffsetDates(List dates, int? offset) /// /// /// The modified list of dates after applying the BYHOUR rules. - private List GetHourVariants(List dates, RecurrencePattern pattern, bool? expand) + private List GetHourVariants(List dates, RecurrencePattern pattern, bool? expand) { if (expand == null || pattern.ByHour.Count == 0) { @@ -709,7 +710,7 @@ private List GetHourVariants(List dates, RecurrencePattern p if (expand.Value) { // Expand behavior - var hourlyDates = new List(); + var hourlyDates = new List(); for (var i = 0; i < dates.Count; i++) { var date = dates[i]; @@ -753,7 +754,7 @@ private List GetHourVariants(List dates, RecurrencePattern p /// /// /// The modified list of dates after applying the BYMINUTE rules. - private List GetMinuteVariants(List dates, RecurrencePattern pattern, bool? expand) + private List GetMinuteVariants(List dates, RecurrencePattern pattern, bool? expand) { if (expand == null || pattern.ByMinute.Count == 0) { @@ -763,7 +764,7 @@ private List GetMinuteVariants(List dates, RecurrencePattern if (expand.Value) { // Expand behavior - var minutelyDates = new List(); + var minutelyDates = new List(); for (var i = 0; i < dates.Count; i++) { var date = dates[i]; @@ -806,7 +807,7 @@ private List GetMinuteVariants(List dates, RecurrencePattern /// /// /// The modified list of dates after applying the BYSECOND rules. - private List GetSecondVariants(List dates, RecurrencePattern pattern, bool? expand) + private List GetSecondVariants(List dates, RecurrencePattern pattern, bool? expand) { if (expand == null || pattern.BySecond.Count == 0) { @@ -816,7 +817,7 @@ private List GetSecondVariants(List dates, RecurrencePattern if (expand.Value) { // Expand behavior - var secondlyDates = new List(); + var secondlyDates = new List(); for (var i = 0; i < dates.Count; i++) { var date = dates[i]; @@ -859,11 +860,11 @@ private List GetSecondVariants(List dates, RecurrencePattern /// where the is taken into account. /// when initializing the new period with a new . /// - private static Period CreatePeriod(DateTime dateTime, CalDateTime referenceDate) + private static Period CreatePeriod(CalDateTime dateTime, CalDateTime referenceDate) { // Turn each resulting date/time into an CalDateTime and associate it // with the reference date. - CalDateTime newDt = new CalDateTime(dateTime, null, referenceDate.HasTime); + var newDt = new CalDateTime(dateTime.Value, null, referenceDate.HasTime); if (referenceDate.TzId != null) { // Adjust nonexistent recurrence instances according to RFC 5545 3.3.5 newDt = newDt.ToTimeZone(referenceDate.TzId); diff --git a/Ical.Net/Evaluation/TodoEvaluator.cs b/Ical.Net/Evaluation/TodoEvaluator.cs index 14c793bec..a1c014cea 100644 --- a/Ical.Net/Evaluation/TodoEvaluator.cs +++ b/Ical.Net/Evaluation/TodoEvaluator.cs @@ -73,9 +73,7 @@ private void DetermineStartingRecurrence(RecurrencePattern recur, ref CalDateTim } else { - var dtVal = referenceDateTime.Value; - IncrementDate(ref dtVal, recur, -recur.Interval); - referenceDateTime = new CalDateTime(DateOnly.FromDateTime(dtVal), TimeOnly.FromDateTime(dtVal)); + IncrementDate(ref referenceDateTime, recur, -recur.Interval); } } diff --git a/Ical.Net/Utility/DateUtil.cs b/Ical.Net/Utility/DateUtil.cs index 52f60a4c7..7bf3ab482 100644 --- a/Ical.Net/Utility/DateUtil.cs +++ b/Ical.Net/Utility/DateUtil.cs @@ -15,7 +15,7 @@ internal static class DateUtil public static CalDateTime AsCalDateTime(this DateTime t) => new CalDateTime(t); - public static DateTime AddWeeks(DateTime dt, int interval, DayOfWeek firstDayOfWeek) + public static CalDateTime AddWeeks(CalDateTime dt, int interval, DayOfWeek firstDayOfWeek) { dt = dt.AddDays(interval * 7); while (dt.DayOfWeek != firstDayOfWeek) @@ -26,7 +26,7 @@ public static DateTime AddWeeks(DateTime dt, int interval, DayOfWeek firstDayOfW return dt; } - public static DateTime FirstDayOfWeek(DateTime dt, DayOfWeek firstDayOfWeek, out int offset) + public static CalDateTime FirstDayOfWeek(CalDateTime dt, DayOfWeek firstDayOfWeek, out int offset) { offset = 0; while (dt.DayOfWeek != firstDayOfWeek)