Skip to content

Commit

Permalink
ical-org#197 Changing RecurrencePattern.Until from DateTime to IDateT…
Browse files Browse the repository at this point in the history
…ime/CalDateTime.
  • Loading branch information
Colin Ng committed Jan 30, 2017
1 parent 73e2ab5 commit 800594d
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 14 deletions.
6 changes: 3 additions & 3 deletions v3/ical.NET.UnitTests/DocumentationExamples.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public void Daily_Test()
//Recur daily through the end of the day, July 31, 2016
var recurrenceRule = new RecurrencePattern(FrequencyType.Daily, 1)
{
Until = DateTime.Parse("2016-07-31T11:59:59")
Until = new CalDateTime(DateTime.Parse("2016-07-31T11:59:59"))
};

vEvent.RecurrenceRules = new List<RecurrencePattern> {recurrenceRule};
Expand Down Expand Up @@ -50,7 +50,7 @@ public void EveryOtherTuesdayUntilTheEndOfTheYear_Test()
// Recurring every other Tuesday until Dec 31
var rrule = new RecurrencePattern(FrequencyType.Weekly, 2)
{
Until = DateTime.Parse("2016-12-31T11:59:59")
Until = new CalDateTime(DateTime.Parse("2016-12-31T11:59:59"))
};
vEvent.RecurrenceRules = new List<RecurrencePattern> { rrule };

Expand Down Expand Up @@ -81,7 +81,7 @@ public void FourthThursdayOfNovember_Tests()
Interval = 1,
ByMonth = new List<int> { 11 },
ByDay = new List<WeekDay> { new WeekDay { DayOfWeek = DayOfWeek.Thursday, Offset = 4 } },
Until = DateTime.MaxValue
Until = new CalDateTime(DateTime.MaxValue)
};
vEvent.RecurrenceRules = new List<RecurrencePattern> { rrule };

Expand Down
6 changes: 3 additions & 3 deletions v3/ical.NET.UnitTests/RecurrenceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2564,7 +2564,7 @@ public void Bug3119920()
var serializer = new RecurrencePatternSerializer();
var rp = (RecurrencePattern)serializer.Deserialize(sr);
var rpe = new RecurrencePatternEvaluator(rp);
var recurringPeriods = rpe.Evaluate(new CalDateTime(start), start, rp.Until, false);
var recurringPeriods = rpe.Evaluate(new CalDateTime(start), start, rp.Until.Value, false);

var period = recurringPeriods.ElementAt(recurringPeriods.Count() - 1);

Expand All @@ -2588,7 +2588,7 @@ public void Bug3178652()

var pattern = new RecurrencePattern {
Frequency = FrequencyType.Monthly,
Until = new DateTime(2011, 12, 25, 0, 0, 0, DateTimeKind.Utc),
Until = new CalDateTime(new DateTime(2011, 12, 25, 0, 0, 0, DateTimeKind.Utc)),
FirstDayOfWeek = DayOfWeek.Sunday,
ByMonthDay = new List<int>(new[] { 29 })
};
Expand Down Expand Up @@ -2957,7 +2957,7 @@ public void OccurrenceMustBeCompletelyContainedWithinSearchRange()

var rrule = new RecurrencePattern(FrequencyType.Weekly, interval: 1)
{
Until = DateTime.Parse("2016-08-31T07:00:00"),
Until = new CalDateTime(DateTime.Parse("2016-08-31T07:00:00")),
ByDay = new List<WeekDay> { new WeekDay(DayOfWeek.Wednesday)},
};

Expand Down
3 changes: 2 additions & 1 deletion v3/ical.NET/DataTypes/RecurrencePattern.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Ical.Net.Interfaces.General;
using Ical.Net.Serialization.iCalendar.Serializers.DataTypes;
using Ical.Net.Utility;
using Ical.Net.Interfaces.DataTypes;

namespace Ical.Net.DataTypes
{
Expand All @@ -20,7 +21,7 @@ public class RecurrencePattern : EncodableDataType

public FrequencyType Frequency { get; set; }

public DateTime Until { get; set; } = DateTime.MinValue;
public IDateTime Until { get; set; } = new CalDateTime(DateTime.MinValue);

public int Count { get; set; } = int.MinValue;

Expand Down
8 changes: 4 additions & 4 deletions v3/ical.NET/Evaluation/RecurrencePatternEvaluator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ private RecurrencePattern ProcessRecurrencePattern(IDateTime referenceDate)
r.CopyFrom(Pattern);

// Convert the UNTIL value to one that matches the same time information as the reference date
if (r.Until != DateTime.MinValue)
if (r.Until.Value != DateTime.MinValue)
{
r.Until = DateUtil.MatchTimeZone(referenceDate, new CalDateTime(r.Until)).Value;
r.Until = DateUtil.MatchTimeZone(referenceDate, r.Until);
}

if (r.Frequency > FrequencyType.Secondly && r.BySecond.Count == 0 && referenceDate.HasTime
Expand Down Expand Up @@ -259,7 +259,7 @@ private HashSet<DateTime> GetDates(IDateTime seed, DateTime periodStart, DateTim
var candidate = DateTime.MinValue;
while ((maxCount < 0) || (dates.Count < maxCount))
{
if (pattern.Until != DateTime.MinValue && candidate != DateTime.MinValue && candidate > pattern.Until)
if (pattern.Until.Value != DateTime.MinValue && candidate != DateTime.MinValue && candidate > pattern.Until.Value)
{
break;
}
Expand Down Expand Up @@ -299,7 +299,7 @@ private HashSet<DateTime> GetDates(IDateTime seed, DateTime periodStart, DateTim
{
break;
}
else if (pattern.Until == DateTime.MinValue || candidate <= pattern.Until)
else if (pattern.Until.Value == DateTime.MinValue || candidate <= pattern.Until.Value)
{
var utcCandidate = DateUtil.FromTimeZoneToTimeZone(candidate, DateUtil.GetZone(seed.TzId), DateTimeZone.Utc).ToDateTimeUtc();
if (!dates.Contains(candidate) && (pattern.Until == DateTime.MinValue || utcCandidate <= pattern.Until))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public override string SerializeToString(object obj)
values.Add("INTERVAL=" + interval);
}

if (recur.Until != DateTime.MinValue)
if (recur.Until.Value != DateTime.MinValue)
{
var serializer = factory.Build(typeof (IDateTime), SerializationContext) as IStringSerializer;
if (serializer != null)
Expand Down Expand Up @@ -250,7 +250,7 @@ public override object Deserialize(TextReader tr)
var dt = serializer?.Deserialize(new StringReader(keyValue)) as IDateTime;
if (dt != null)
{
r.Until = dt.Value;
r.Until.Value = dt.Value;
}
}
break;
Expand Down Expand Up @@ -449,7 +449,7 @@ public override object Deserialize(TextReader tr)
var dt = DateTime.Parse(match.Groups["DateTime"].Value);
DateTime.SpecifyKind(dt, DateTimeKind.Utc);

r.Until = dt;
r.Until.Value = dt;
}
else if ((match = SpecificRecurrenceCount.Match(item)).Success)
{
Expand Down

0 comments on commit 800594d

Please sign in to comment.