protected virtual ReminderEntity CreateReminderEntity() { DateTime scheduledDateTime = GetDateTimeFromUI(); DateTime scheduledDateTimeUtc = ConvertFromLocalToUtc(scheduledDateTime); //create bool array from the checkbox list bool[] repeatWeeklyDays = new bool[7]; foreach (int checkedIndex in repeatWeeklyCheckedListBox.CheckedIndices) { repeatWeeklyDays[checkedIndex] = true; } //disable weekly flag if 0 days are selected bool repeatWeekly = AnyChecked(repeatWeeklyDays); RepeatPeriod repeatPeriod = GetRepeatPeriod(repeatWeekly); var reminderEntity = new ReminderEntity() { Name = SanitizeReminderName(reminderNameStringBox.Text), ScheduledTime = scheduledDateTimeUtc, RepeatPeriod = repeatPeriod, RepeatWeeklyDays = repeatWeeklyDays }; return(reminderEntity); }
// TODO: HIGH: I think the decision to go with events / series etc makes it impossible to use entities here (or public override IEnumerable <DateTime> Occur(RepeatPeriod repeatPeriod, DateTime eventStart, DateTime repeatFrom, DateTime repeatTill) { var occurrences = new List <DateTime>(); var latestTime = eventStart; var effectiveEnd = DateTime.Compare(repeatTill, TimeWhenFinished) < 0 ? repeatTill : TimeWhenFinished; while (latestTime < effectiveEnd) { if (latestTime > repeatFrom) { occurrences.Add(latestTime); } latestTime = latestTime.Add(repeatPeriod.NextOccurence(latestTime).Subtract(latestTime)); } return(occurrences); }
public override IEnumerable <DateTime> Occur(RepeatPeriod repeatPeriod, DateTime eventStart, DateTime repeatFrom, DateTime repeatTill) { var latestDate = eventStart; var occurrences = new List <DateTime>(); var timesToOccur = MaxTimesToOccur; while (timesToOccur > 0 && latestDate <= repeatTill) { if (latestDate > repeatFrom) { occurrences.Add(latestDate); } latestDate = latestDate.Add(repeatPeriod.NextOccurence(latestDate).Subtract(latestDate)); timesToOccur--; } return(occurrences); }
public override IEnumerable <DateTime> Occur(RepeatPeriod repeatPeriod, DateTime eventStart, DateTime repeatFrom, DateTime repeatTill) { var occurrences = new List <DateTime>(); var latestTime = eventStart; // TODO: HIGH : Not very readable code. I would try to hint the reader that we are trying to find the start time // for generating occurances. Possibly encapsulate the logic in RepeatPeriod to find the closest occurance to a given date and start from there. while (latestTime < repeatTill) { if (latestTime > repeatFrom) { occurrences.Add(latestTime); } latestTime = latestTime.Add(repeatPeriod.NextOccurence(latestTime).Subtract(latestTime)); } return(occurrences); }
public static DateTime NextOccurence(this RepeatPeriod period, DateTime previousDate) { switch (period) { // TODO: HIGH : Better modeled as classes perhaps. You can map incoming model / DB entity to class. case RepeatPeriod.Day: return(previousDate.AddDays(1)); // TODO: HIGH: Weekly shceduling not complete - explicit days of week was the interesting scenario as mentioned in the task. case RepeatPeriod.Week: return(previousDate.AddDays(7)); case RepeatPeriod.Month: return(previousDate.AddMonths(1)); case RepeatPeriod.Year: return(previousDate.AddYears(1)); default: throw new ArgumentOutOfRangeException(nameof(period), period, null); } }
public Repeat(RepeatPeriod repeatPeriod, DateTime endDay) { EndDate = endDay; RepeatPeriod = repeatPeriod; }
public Repeat(DateTime startDay, DateTime endDay, RepeatPeriod repeatPeriod) { StartDay = startDay; EndDate = endDay; RepeatPeriod = repeatPeriod; }
Occur(RepeatPeriod repeatPeriod, DateTime eventStart, DateTime repeatFrom, DateTime repeatTill);