public override void HandleYearUpdate(IDateProvider dateProvider) { this.Year = dateProvider.GetToday().Year; var iteratorDate = new DateTime(this.Year, this.Month, FIRST_DAY_OF_MONTH); var nextMonth = iteratorDate.Month + 1; var weekCounter = FIRST_WEEK_OF_MONTH; while (iteratorDate.Month < nextMonth) { var matchingWeekday = iteratorDate.DayOfWeek == this.DayOfWeek; if (matchingWeekday) { bool matchingNthWeek = weekCounter == this.NthWeek; if (matchingNthWeek) { this.DateOfCalItemThisYear = iteratorDate; return; } weekCounter++; } iteratorDate = iteratorDate.AddDays(1); } throw new CannotFindDateNextYearException($"Unable to find the {this.NthWeek}th {this.DayOfWeek.ToString()} of {this.Month.ToString()} {this.Year.ToString()}"); }
private List <CalendarSummaryItem> GetItems(int daysAway) { return(this.Items.Where(calItem => { if (_dateProvider.GetToday().AddDays(daysAway) == calItem.DateOfCalItemThisYear) { return true; } return false; }).ToList()); }
public void AddContextHeader() { var dateString = _dateProvider.GetToday().ToString("MMMM dd, yyyy"); var text = $"Your event summary for {dateString}"; var elements = new List <Element> () { new Element(type: "mrkdwn", text) }; var block = new Block(type: "context", text: null, elements, fields: null); AddBlock(block); }
public List <CalendarSummaryItem> GetItems() { var today = _dateProvider.GetToday(); var items = _calendarItemProvider.GetItems(); var datesForThisYear = GetDatesForCurrentYear(items); if (!datesForThisYear.Any()) { return(new List <CalendarSummaryItem> ()); } var nthDayOfMonthRules = datesForThisYear .Where(p => p is NthDayOfMonthCalendarItem) .Select(p => (NthDayOfMonthCalendarItem)p).ToList(); var nthWeekdayOfMonthRules = datesForThisYear .Where(p => p is NthWeekdayOfMonthCalendarItem) .Select(p => (NthWeekdayOfMonthCalendarItem)p).ToList(); var remindersToReturn = new List <CalendarSummaryItem> (); foreach (var date in datesForThisYear) { foreach (var reminder in date.RemindAtCsv.Split(',')) { if (reminder.Length != 2) { throw new ArgumentException("Reminder length is not length of 2. Configuration is wrong."); } if (IsDueForReminder(date, reminder) && !remindersToReturn.Contains(date.ToCalendarSummaryItem())) { remindersToReturn.Add(date.ToCalendarSummaryItem()); } } } return(remindersToReturn); }
public override void HandleYearUpdate(IDateProvider dateProvider) { this.Year = dateProvider.GetToday().Year; this.DateOfCalItemThisYear = new DateTime(this.Year, this.Month, this.Day); }