private bool CheckDate(DateTime d) { if (ByMonth != null && !ByMonth.Contains(d.Month)) { return(false); } //only for YEARLY if (ByWeekNo != null) { var weekOfYear = d.GetWeekOfYear(this.WKST.DayOfWeek); if (!ByWeekNo.Contains(weekOfYear) && !ByWeekNo.Contains(weekOfYear - (d.GetWeekOfYearCount(this.WKST.DayOfWeek) + 1))) { return(false); } } if (ByYearDay != null && !ByYearDay.Contains(d.DayOfYear) && !ByYearDay.Contains(d.DayOfYear - (d.GetDaysInYear() + 1))) { return(false); } if (ByMonthDay != null && !ByMonthDay.Contains(d.Day) && !ByMonthDay.Contains(d.Day - d.GetDaysInMonth() + 1)) { return(false); } if (ByDay != null && !ByDay.ToList().Exists(item => item.DayOfWeek == d.DayOfWeek)) { return(false); } return(true); }
//------------------------------------------------------------------------------------------- private void BindByDay() { string expensesByDay = @"select year(postat) as 'Year', month(postat) as 'Month', day(postat) as 'Day', Sum(Amount) as 'Total' from Accounting_LedgerItems where OrganizationId = @OrganizationId and LedgerType != @Receivable and LedgerType = @CreditCard and Year(postat) = @Year Group By Year(PostAt), Month(PostAt), Day(PostAt) Order By Year(PostAt) desc, Month(PostAt) desc, Day(PostAt) desc"; { SqlCommand command = new SqlCommand(expensesByDay, connection); command.Parameters.AddWithValue("OrganizationId", SelectedOrganization.Id); command.Parameters.AddWithValue("Year", Int32.Parse(YearFilter.Text)); command.Parameters.AddWithValue("Receivable", (byte)LedgerType.Receivable); command.Parameters.AddWithValue("CreditCard", (byte)LedgerType.CreditCard); SqlDataReader reader = command.ExecuteReader(); ByDay.DataSource = reader; ByDay.DataBind(); reader.Close(); } }
public IntervalRecurrencePattern(ZoneInterval interval) { Frequency = FrequencyType.Yearly; ByMonth.Add(interval.IsoLocalStart.Month); var date = interval.IsoLocalStart.ToDateTimeUnspecified(); var weekday = date.DayOfWeek; var num = DateUtil.WeekOfMonth(date); ByDay.Add(num != 5 ? new WeekDay(weekday, num) : new WeekDay(weekday, -1)); }
public override int GetHashCode() { var hashCode = ByDay.GetHashCode() ^ ByHour.GetHashCode() ^ ByMinute.GetHashCode() ^ ByMonth.GetHashCode() ^ ByMonthDay.GetHashCode() ^ BySecond.GetHashCode() ^ BySetPosition.GetHashCode() ^ ByWeekNo.GetHashCode() ^ ByYearDay.GetHashCode() ^ Count.GetHashCode() ^ Frequency.GetHashCode(); if (Interval.Equals(1)) { hashCode ^= 0x1; } else { hashCode ^= Interval.GetHashCode(); } hashCode ^= Until.GetHashCode(); hashCode ^= FirstDayOfWeek.GetHashCode(); return(hashCode); }
public List <DateTime> GetDates(DateTime utcStartDate, DateTime fromDate, DateTime toDate, int maxCount, bool removeExDates = true) { var dates = new List <DateTime>(); var endDate = (this.Until == DateTime.MinValue ? toDate : (toDate > this.Until ? this.Until : toDate)); //push start date dates.Add(utcStartDate); DateTime d; switch (Freq) { case Frequency.Secondly: #region Secondly d = utcStartDate.AddSeconds(this.Interval); while (d <= endDate && CheckCount(dates, fromDate, maxCount)) { if (CheckDate(d) && (ByHour == null || (ByHour != null && ByHour.Contains(d.Hour))) && (ByMinute == null || (ByMinute != null && ByMinute.Contains(d.Minute))) && (BySecond == null || (BySecond != null && BySecond.Contains(d.Second)))) { if (d >= utcStartDate && d <= endDate && !dates.Contains(d)) { dates.Add(d); } } d = d.AddMinutes(this.Interval); } break; #endregion case Frequency.Minutely: #region Minutely d = utcStartDate.AddMinutes(this.Interval); while (d <= endDate && CheckCount(dates, fromDate, maxCount)) { if (CheckDate(d) && (ByHour == null || (ByHour != null && ByHour.Contains(d.Hour))) && (ByMinute == null || (ByMinute != null && ByMinute.Contains(d.Minute)))) { //seconds var seconds = new List <int>(); if (BySecond != null) { seconds.AddRange(BySecond); } else { seconds.Add(d.Second); } foreach (var s in seconds) { var newDate = new DateTime(d.Year, d.Month, d.Day, d.Hour, d.Minute, s); if (newDate >= utcStartDate && newDate <= endDate && !dates.Contains(newDate)) { dates.Add(newDate); } } } d = d.AddMinutes(this.Interval); } break; #endregion case Frequency.Hourly: #region Hourly d = utcStartDate.AddHours(this.Interval); while (d <= endDate && CheckCount(dates, fromDate, maxCount)) { if (CheckDate(d) && (ByHour == null || (ByHour != null && ByHour.Contains(d.Hour)))) { //minutes var minutes = new List <int>(); if (ByMinute != null) { minutes.AddRange(ByMinute); } else { minutes.Add(d.Minute); } //seconds var seconds = new List <int>(); if (BySecond != null) { seconds.AddRange(BySecond); } else { seconds.Add(d.Second); } foreach (var m in minutes) { foreach (var s in seconds) { var newDate = new DateTime(d.Year, d.Month, d.Day, d.Hour, m, s); if (newDate >= utcStartDate && newDate <= endDate && !dates.Contains(newDate)) { dates.Add(newDate); } } } } d = d.AddHours(this.Interval); } break; #endregion case Frequency.Daily: #region Daily d = utcStartDate.AddDays(this.Interval); while (d <= endDate && CheckCount(dates, fromDate, maxCount)) { if (CheckDate(d)) { GetDatesWithTime(ref dates, utcStartDate, endDate, d, new List <DateTime>() { d }); } d = d.AddDays(this.Interval); } break; #endregion case Frequency.Weekly: #region Weekly d = utcStartDate; while (d <= endDate && CheckCount(dates, fromDate, maxCount)) { var dateRange = new List <DateTime>(); for (var i = 0; i < 7; i++) { dateRange.Add(d.AddDays(i)); } if (ByMonth != null) { dateRange.RemoveAll(date => !ByMonth.Contains(date.Month)); } if (ByYearDay != null) { dateRange.RemoveAll(date => (!ByYearDay.Contains(date.DayOfYear) && !ByYearDay.Contains(date.DayOfYear - (date.GetDaysInYear() + 1)))); } if (ByMonthDay != null) { dateRange.RemoveAll(date => (!ByMonthDay.Contains(date.Day) && !ByMonthDay.Contains(date.Day - (date.GetDaysInMonth() + 1)))); } if (ByDay != null) { dateRange.RemoveAll(date => !ByDay.ToList().Exists(wd => wd.DayOfWeek == date.DayOfWeek)); } if (ByDay == null && ByMonthDay == null && ByYearDay == null) { dateRange.RemoveAll(date => date.Day != d.Day); } GetDatesWithTime(ref dates, utcStartDate, endDate, d, dateRange); d = d.AddDays(7 * this.Interval); } break; #endregion case Frequency.Monthly: #region Monthly d = utcStartDate; while (d <= endDate && CheckCount(dates, fromDate, maxCount)) { var dateRange = new List <DateTime>(); if (ByMonth != null && !ByMonth.Contains(d.Month)) { d = d.AddMonths(this.Interval); continue; } var day = new DateTime(d.Year, d.Month, 1); while (day.Month == d.Month) { dateRange.Add(day); day = day.AddDays(1); } if (ByYearDay != null) { dateRange.RemoveAll(date => (!ByYearDay.Contains(date.DayOfYear) && !ByYearDay.Contains(date.DayOfYear - (date.GetDaysInYear() + 1)))); } if (ByMonthDay != null) { dateRange.RemoveAll(date => (!ByMonthDay.Contains(date.Day) && !ByMonthDay.Contains(date.Day - (date.GetDaysInMonth() + 1)))); } //only for MONTHLY or YEARLY if (ByDay != null) { var listDates = new List <DateTime>(); foreach (var date in ByDay) { listDates.AddRange(date.GetDates(new DateTime(d.Year, d.Month, 1), true)); } dateRange.RemoveAll(date => !listDates.Contains(date)); } if (ByDay == null && ByMonthDay == null && ByYearDay == null) { dateRange.RemoveAll(date => date.Day != d.Day); } GetDatesWithTime(ref dates, utcStartDate, endDate, d, dateRange); d = d.AddMonths(this.Interval); } break; #endregion case Frequency.Yearly: #region Yearly d = utcStartDate; if (d.Month == 2 && d.Day == 29) { if (Interval == 1 && ByMonth == null && ByWeekNo == null && ByYearDay == null && ByMonthDay == null && ByDay == null) { Interval = 4; } } while (d.Year <= endDate.Year && CheckCount(dates, fromDate, maxCount)) { var dateRange = new List <DateTime>(); bool isFirst = true; if (ByMonth != null) { foreach (var m in ByMonth) { var date = new DateTime(d.Year, m, 1); while (date.Month == m) { dateRange.Add(date); date = date.AddDays(1); } } isFirst = false; } //only for YEARLY if (ByWeekNo != null) { if (isFirst) { var date = new DateTime(d.Year, 1, 1); while (date.Year == d.Year) { var weekOfYear = date.GetWeekOfYear(this.WKST.DayOfWeek); if (ByWeekNo.Contains(weekOfYear) || ByWeekNo.Contains(weekOfYear - (date.GetWeekOfYearCount(this.WKST.DayOfWeek) + 1))) { dateRange.Add(date); } date = date.AddDays(1); } } else { dateRange.RemoveAll(date => { var weekOfYear = date.GetWeekOfYear(this.WKST.DayOfWeek); return((!ByWeekNo.Contains(weekOfYear) && !ByWeekNo.Contains(weekOfYear - (date.GetWeekOfYearCount(this.WKST.DayOfWeek) + 1)))); }); } isFirst = false; } if (ByYearDay != null) { if (isFirst) { foreach (var yearDay in ByYearDay) { dateRange.Add(new DateTime(d.Year, 1, 1).AddDays((yearDay > 0 ? yearDay : (d.GetDaysInYear() + yearDay)) - 1)); } } else { dateRange.RemoveAll(date => (!ByYearDay.Contains(date.DayOfYear) && !ByYearDay.Contains(date.DayOfYear - (date.GetDaysInYear() + 1)))); } isFirst = false; } if (ByMonthDay != null) { if (isFirst) { for (var m = 1; m <= 12; m++) { foreach (var day in ByMonthDay) { var dd = new DateTime(d.Year, m, 1); dateRange.Add(dd.AddDays((day > 0 ? day : (dd.GetDaysInMonth() + day)) - 1)); } } } else { dateRange.RemoveAll(date => (!ByMonthDay.Contains(date.Day) && !ByMonthDay.Contains(date.Day - (date.GetDaysInMonth() + 1)))); } isFirst = false; } //only for MONTHLY or YEARLY if (ByDay != null) { var listDates = new List <DateTime>(); foreach (var day in ByDay) { listDates.AddRange(day.GetDates(new DateTime(d.Year, 1, 1), false)); } listDates.Sort(); if (isFirst) { dateRange.AddRange(listDates); } else { dateRange.RemoveAll(date => !listDates.Contains(date)); } isFirst = false; } if (ByDay == null && ByMonthDay == null && ByYearDay == null && ByWeekNo == null) { dateRange.RemoveAll(date => date.Day != d.Day); } //add yearly same date if (isFirst) { dateRange.Add(d); } GetDatesWithTime(ref dates, utcStartDate, endDate, d, dateRange); d = d.AddYears(this.Interval); } break; #endregion } if (Count >= 0) { var count = this.Count; dates = dates.FindAll(date => (--count) >= 0); } if (removeExDates && ExDates != null) { foreach (var exDate in ExDates) { dates.RemoveAll(dt => (exDate.isDateTime && dt == exDate.Date) || (!exDate.isDateTime && dt.Date == exDate.Date)); } } dates.RemoveAll(dt => dt <fromDate || dt> endDate); return(dates); }