Beispiel #1
0
        protected DateTime[] GetDates(IRepository repository)
        {
            List <DateTime> dates = new List <DateTime>();

            DateTime min = repository.Queryable <Commit>().Min(c => c.Date);
            DateTime max = repository.Queryable <Commit>().Max(c => c.Date);

            DateTime date = min;

            switch (DatePeriod)
            {
            case DatePeriod.DAY: date = date.StartOfDay(); break;

            case DatePeriod.WEEK: date = date.StartOfWeek(); break;

            case DatePeriod.MONTH: date = date.StartOfMonth(); break;

            case DatePeriod.QUARTER: date = date.StartOfQuarter(); break;

            case DatePeriod.YEAR: date = date.StartOfYear(); break;

            default: break;
            }

            DateTime prevDate = date;

            while (prevDate < max)
            {
                dates.Add(date);
                prevDate = date;
                switch (DatePeriod)
                {
                case DatePeriod.DAY: date = date.AddDays(1); break;

                case DatePeriod.WEEK: date = date.AddWeeks(1); break;

                case DatePeriod.MONTH: date = date.AddMonths(1); break;

                case DatePeriod.QUARTER: date = date.AddQuarters(1); break;

                case DatePeriod.YEAR: date = date.AddYears(1); break;

                default: break;
                }
            }

            if (dates.Count > 0 && dates.First() < min)
            {
                dates[0] = min;
            }
            if (dates.Count > 1 && dates.Last() > max)
            {
                dates[dates.Count - 1] = max;
            }

            return(dates.ToArray());
        }
 /// <summary>
 /// Получение конца квартала
 /// </summary>
 /// <param name="date">Дата и время</param>
 /// <returns></returns>
 public static DateTime EndOfQuarter(this DateTime date)
 {
     return(date.AddQuarters(1).StartOfQuarter().AddDays(-1).EndOfDay());
 }
Beispiel #3
0
 public DateTime AddQuartersTest(DateTime dateTime, int quarters)
 {
     return(dateTime.AddQuarters(quarters));
 }