/// <summary>
        /// Gets the date that the series should actually start on. Might be different than user picked start date due to weekly occurrence allowing you to pick a day that isn't the start date.
        /// </summary>
        /// <param name="userPickedStartDate"></param>
        /// <returns></returns>
        public DateTime GetStartDate(DateTime userPickedStartDate)
        {
            switch (SelectedRepeatOption)
            {
            // For weekly, they might have selected a day of the week that starts later, so have to find the closest next date
            case RepeatOptions.Weekly:

                DayOfWeek[] selectedDaysOfWeek = GetSelectedDaysOfWeek();
                if (selectedDaysOfWeek.Length == 0)
                {
                    throw new InvalidOperationException("No days of week were selected");
                }
                DateTime closest = DateTime.MaxValue;

                foreach (var day in selectedDaysOfWeek)
                {
                    DateTime potentialClosest = DateTools.Next(day, userPickedStartDate);
                    if (potentialClosest < closest)
                    {
                        closest = potentialClosest;
                    }
                }

                return(closest);

            default:
                return(userPickedStartDate.Date);
            }
        }
Example #2
0
            public GroupedDay(MyObservableList <ViewItemSchedule> allSchedules, DayOfWeek dayOfWeek)
            {
                DayOfWeek = dayOfWeek;

                var date = DateTools.Next(dayOfWeek, DateTime.Today);

                Times = allSchedules.Sublist(i => i.OccursOnDate(date));
                Times.CollectionChanged += Schedules_CollectionChanged;

                ResetVisibility();
            }
        public DateTime GetLocalStartDateAndTime(AccountDataItem account, DataItemSemester semester, DataItemClass c)
        {
            DateTime startDate;

            if (!DateValues.IsUnassigned(semester.Start))
            {
                startDate = DateHelpers.ToViewItemTime(account, semester.Start);
            }
            else
            {
                startDate = DateTime.Today.AddYears(-1);
            }

            // If the class has a start date, we use that rather than the semester start date
            if (!DateValues.IsUnassigned(c.StartDate))
            {
                startDate = DateHelpers.ToViewItemTime(account, c.StartDate);
            }

            var currentWeek = account.GetWeekOnDifferentDate(startDate);

            // If the schedule doesn't occur each week
            if (this.ScheduleWeek != Schedule.Week.BothWeeks)
            {
                // If it's on the wrong week, we'll move it forward 7 days
                if (currentWeek != this.ScheduleWeek)
                {
                    startDate = startDate.AddDays(7);
                }
            }

            // Get the date the schedule actually starts on
            startDate = DateTools.Next(this.DayOfWeek, startDate);

            return(startDate.Add(this.StartTime.TimeOfDay));
        }