-
Notifications
You must be signed in to change notification settings - Fork 249
Expand file tree
/
Copy pathEvaluator.cs
More file actions
59 lines (54 loc) · 2.21 KB
/
Evaluator.cs
File metadata and controls
59 lines (54 loc) · 2.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
//
// Copyright ical.net project maintainers and contributors.
// Licensed under the MIT license.
//
using System;
using System.Collections.Generic;
using Ical.Net.DataTypes;
using Ical.Net.Utility;
namespace Ical.Net.Evaluation;
public abstract class Evaluator : IEvaluator
{
protected void IncrementDate(ref CalDateTime dt, RecurrencePattern pattern, int interval)
{
if (interval == 0)
return;
try
{
var old = dt;
switch (pattern.Frequency)
{
case FrequencyType.Secondly:
dt = old.AddSeconds(interval);
break;
case FrequencyType.Minutely:
dt = old.AddMinutes(interval);
break;
case FrequencyType.Hourly:
dt = old.AddHours(interval);
break;
case FrequencyType.Daily:
dt = old.AddDays(interval);
break;
case FrequencyType.Weekly:
dt = DateUtil.AddWeeks(old, interval, pattern.FirstDayOfWeek);
break;
case FrequencyType.Monthly:
dt = old.AddDays(-old.Day + 1).AddMonths(interval);
break;
case FrequencyType.Yearly:
dt = old.AddDays(-old.DayOfYear + 1).AddYears(interval);
break;
// FIXME: use a more specific exception.
default:
throw new Exception("FrequencyType.NONE cannot be evaluated. Please specify a FrequencyType before evaluating the recurrence.");
}
}
catch (ArgumentOutOfRangeException)
{
// intentionally don't include the outer exception
throw new EvaluationOutOfRangeException("Evaluation aborted: The maximum supported date-time was exceeded while enumerating a recurrence rule. This commonly happens when trying to enumerate an unbounded RRULE to its end. Consider applying the .TakeWhile() operator.");
}
}
public abstract IEnumerable<Period> Evaluate(CalDateTime referenceDate, CalDateTime? periodStart, EvaluationOptions? options);
}