Esempio n. 1
0
        private static IEnumerable <DateTime> GetOccurrences(DateInterval interval, DatePeriod period, Calendar calendar,
                                                             DateTime start, DateTime end, bool skipWeekends = true)
        {
            var difference = DateSpan.GetDifference(interval, start, end) / period.Quantifier;

            if (start.Kind == DateTimeKind.Utc)
            {
                start = start.ToLocalTime();
            }

            for (var i = 0; i < difference; i++)
            {
                switch (period.Frequency)
                {
                case DatePeriodFrequency.Seconds:
                    var seconds = calendar.AddSeconds(start, period.Quantifier * i);
                    yield return(DeferOccurrenceFallingOnWeekend(calendar, seconds, skipWeekends));

                    break;

                case DatePeriodFrequency.Minutes:
                    var minutes = calendar.AddMinutes(start, period.Quantifier * i);
                    yield return(DeferOccurrenceFallingOnWeekend(calendar, minutes, skipWeekends));

                    break;

                case DatePeriodFrequency.Hours:
                    var hours = calendar.AddHours(start, period.Quantifier * i);
                    yield return(DeferOccurrenceFallingOnWeekend(calendar, hours, skipWeekends));

                    break;

                case DatePeriodFrequency.Days:
                    var days = calendar.AddDays(start, period.Quantifier * i);
                    yield return(DeferOccurrenceFallingOnWeekend(calendar, days, skipWeekends));

                    break;

                case DatePeriodFrequency.Weeks:
                    var weeks = calendar.AddWeeks(start, period.Quantifier * i);
                    yield return(DeferOccurrenceFallingOnWeekend(calendar, weeks, skipWeekends));

                    break;

                case DatePeriodFrequency.Months:
                    var months = calendar.AddMonths(start, period.Quantifier * i);
                    yield return(DeferOccurrenceFallingOnWeekend(calendar, months, skipWeekends));

                    break;

                case DatePeriodFrequency.Years:
                    var years = calendar.AddYears(start, period.Quantifier * i);
                    yield return(DeferOccurrenceFallingOnWeekend(calendar, years, skipWeekends));

                    break;

                default:
                    throw new ArgumentException("Frequency");
                }
            }
        }
Esempio n. 2
0
 private static IEnumerable <DateTimeOffset> GetOccurrences(DateInterval interval, DatePeriod period,
                                                            Calendar calendar, DateTimeOffset start, DateTimeOffset end, bool skipWeekends = true)
 {
     return(GetOccurrences(interval, period, calendar, start.DateTime, end.DateTime, skipWeekends)
            .Select(occurrence => (DateTimeOffset)occurrence));
 }