Example #1
0
        internal static DateTime?GetNextOccurrence(this DateTime dateTime, WeeklyPatternModel weeklyPattern)
        {
            DateTime currentDate = dateTime.AddDays(1);

            while (currentDate <= weeklyPattern.EndDate)
            {
                if (weeklyPattern.Days.Contains(currentDate.DayOfWeek))
                {
                    return(currentDate);
                }

                currentDate = currentDate.AddDays(1);
            }

            return(null);
        }
Example #2
0
        public IEnumerable <DiaryEventModel> CreateSeries(WeeklyPatternModel weeklyPattern, DateTime endDate)
        {
            var series = new List <DiaryEventModel>();

            series.Add(this);

            DateTime?nextStartTime = StartTime.GetNextOccurrence(weeklyPattern);
            TimeSpan duration      = EndTime - StartTime;

            while (nextStartTime.HasValue && nextStartTime <= endDate)
            {
                var newEvent = (DiaryEventModel)Clone();
                newEvent.StartTime = nextStartTime.Value;
                newEvent.EndTime   = nextStartTime.Value.Add(duration);
                series.Add(newEvent);

                nextStartTime = nextStartTime.Value.GetNextOccurrence(weeklyPattern);
            }

            return(series);
        }