/// <summary> /// If no schedules on that day, returns null. /// </summary> /// <param name="date"></param> /// <param name="classes"></param> /// <returns></returns> public DateTime?GetClassEndTime(DateTime date, IEnumerable <ViewItemClass> classes) { date = DateTime.SpecifyKind(date.Date, DateTimeKind.Local); //if they're using custom end times if (this.CustomEndTimes.ContainsKey(date.DayOfWeek)) { return(date.Add(this.CustomEndTimes[date.DayOfWeek])); } PowerPlannerSending.Schedule.Week week = this.GetWeekOnDifferentDate(date); //otherwise get all the schedules IEnumerable <ViewItemSchedule> schedules; schedules = classes.SelectMany(i => i.Schedules).Where(i => i.DayOfWeek == date.DayOfWeek && (i.ScheduleWeek == week || i.ScheduleWeek == PowerPlannerSending.Schedule.Week.BothWeeks)).ToArray(); //if there aren't any schedules on that day if (!schedules.Any()) { return(null); } return(date.Add(schedules.Max(i => i.EndTime.TimeOfDay))); }
private static DateTime GetDayBeforeReminderTime(DateTime date, AccountDataItem account, IEnumerable <ViewItemSchedule> allSchedules) { date = DateTime.SpecifyKind(date.Date, DateTimeKind.Local); //if they're using custom end times if (account.CustomEndTimes.ContainsKey(date.DayOfWeek)) { return(date.Add(account.CustomEndTimes[date.DayOfWeek]).AddMinutes(10)); } PowerPlannerSending.Schedule.Week week = account.GetWeekOnDifferentDate(date); //otherwise get all the schedules IEnumerable <ViewItemSchedule> schedules; schedules = allSchedules.Where(i => i.DayOfWeek == date.DayOfWeek && (i.ScheduleWeek == week || i.ScheduleWeek == PowerPlannerSending.Schedule.Week.BothWeeks)); // If there aren't any schedules on that day if (!schedules.Any()) { return(date.AddHours(15)); // 3:00 PM is default time for day before reminders } return(date.Add(schedules.Max(i => i.EndTime.TimeOfDay)).AddMinutes(10)); //day before reminders show up 10 mins after last class }
private static DateTime GetDayOfReminderTime(PowerPlannerSending.Schedule.Week weekOnItemDate, BaseViewItemHomeworkExam item) { bool hadSpecificTime; return(item.GetDayOfReminderTime(out hadSpecificTime)); }
/// <summary> /// Returns a list of items that should have active notifications (ignoring whether user already dismissed them) /// </summary> /// <param name="account"></param> /// <param name="agendaItems"></param> /// <param name="now"></param> /// <param name="nextReminderTime"></param> /// <returns></returns> private static List <Tuple <BaseViewItemHomeworkExam, DateTime> > GetItemsThatCouldHaveDayOfNotifications(AccountDataItem account, AgendaViewItemsGroup agendaItems, DateTime now, out DateTime nextReminderTime) { List <Tuple <BaseViewItemHomeworkExam, DateTime> > shouldBeActive = new List <Tuple <BaseViewItemHomeworkExam, DateTime> >(); nextReminderTime = DateTime.MinValue; PowerPlannerSending.Schedule.Week currentWeek = account.GetWeekOnDifferentDate(now); // Add past-due incomplete tasks (we don't add exams since they're "complete" when they're past-due) foreach (var task in agendaItems.Items.OfType <ViewItemHomework>().Where(i => i.Date.Date < now.Date).OrderBy(i => i)) { shouldBeActive.Add(new Tuple <BaseViewItemHomeworkExam, DateTime>(task, task.Date.Date)); } // Look at items due today // NOTE: Assuming that end time is always on the same day. If we allow events that span multiple days, // we might need to update this so it correctly expires the event on the future date. // To make sure we include items due 00:30 on the next day, we have to factor in tomorrow DateTime tomorrow = now.Date.AddDays(1); var weekForTomorrow = account.GetWeekOnDifferentDate(tomorrow); foreach (var item in agendaItems.Items.Where(i => i.Date.Date == now.Date || i.Date.Date == tomorrow).OrderBy(i => i)) { // Get the reminder time DateTime reminderTime = GetDayOfReminderTime(item.Date.Date == tomorrow ? weekForTomorrow : currentWeek, item); // If it's past the reminder time if (now >= reminderTime) { // If it has an end time DateTime endTime; if (item.TryGetEndDateWithTime(out endTime)) { // We have to consider the end time for updating reminders, since events // expire once they're over (so need to update again right when an event completes) if (endTime > now && (nextReminderTime == DateTime.MinValue || endTime < nextReminderTime)) { shouldBeActive.Add(new Tuple <BaseViewItemHomeworkExam, DateTime>(item, reminderTime)); nextReminderTime = endTime; } } else { // Otherwise add it shouldBeActive.Add(new Tuple <BaseViewItemHomeworkExam, DateTime>(item, reminderTime)); } } else if (nextReminderTime == DateTime.MinValue || reminderTime < nextReminderTime) { nextReminderTime = reminderTime; } } // If no time found, we pick an item that's due in the future if (nextReminderTime == DateTime.MinValue) { DateTime?nextDateWithItems = agendaItems.Items.Where(i => i.Date.Date > now.Date).OrderBy(i => i.Date.Date).FirstOrDefault()?.Date.Date; if (nextDateWithItems != null) { // Get the week for that date var week = account.GetWeekOnDifferentDate(nextDateWithItems.Value); // Look through all items on that date foreach (var item in agendaItems.Items.Where(i => i.Date.Date == nextDateWithItems.Value)) { // Pick the smallest reminder time DateTime reminderTime = GetDayOfReminderTime(currentWeek, item); if (nextReminderTime == DateTime.MinValue || reminderTime < nextReminderTime) { nextReminderTime = reminderTime; } } } } return(shouldBeActive); }
private static DateTime GetDayOfReminderTime(PowerPlannerSending.Schedule.Week weekOnItemDate, ViewItemTaskOrEvent item) { bool hadSpecificTime; return(item.GetDayOfReminderTime(out hadSpecificTime)); }