Exemplo n.º 1
0
 /// <summary>
 /// Creates  a range that is 
 /// </summary>
 /// <param name="monthRange"></param>
 /// <param name="weekRange"></param>
 /// <returns></returns>
 public static DateRange CreateRangeUnion(DateRange monthRange, DateRange weekRange)
 {
     DateTime starts = monthRange.StartDate;
     DateTime ends = monthRange.EndDate;
     if (weekRange.EndDate.Date > monthRange.EndDate.Date)
         ends = weekRange.EndDate;
     int totalDays = (ends - starts).Days;
     return CreateForXDays(totalDays + 2, starts);
 }
Exemplo n.º 2
0
 /// <summary>
 /// Range of 2 days, today and tomorrow.
 /// </summary>
 /// <returns></returns>
 public static DateRange CreateTodayTomorrow()
 {
     DateRange range = new DateRange();
     range.StartDate = DateTime.Today;
     range.EndDate = DateHelper.GetEndOfTomorrow();
     range.Dates = new List<DateTime>();
     range.DatesToIndex = new Dictionary<DateTime, int>();
     range.Dates.Add(range.StartDate);
     range.DatesToIndex.Add(range.StartDate, 0);
     range.Dates.Add(range.EndDate);
     range.DatesToIndex.Add(range.EndDate, 1);
     range.RangeSize = 2;
     return range;
 }
Exemplo n.º 3
0
 /// <summary>
 /// Creaes the last range from the current range supplied.
 /// </summary>
 /// <param name="current"></param>
 /// <param name="isMonthBased"></param>
 /// <returns></returns>
 public static DateRange CreatePriorRange(DateRange current, bool isMonthBased)
 {
     if (isMonthBased)
     {
         DateRangeMonth monthRange = current as DateRangeMonth;
         return CreateForPriorMonth(monthRange);
     }
     DateTime startDate = current.StartDate.Date.AddDays(- current.RangeSize);
     return CreateForXDays(current.RangeSize, startDate);
 }
Exemplo n.º 4
0
 /// <summary>
 /// Creates the next range from the current range supplied.
 /// </summary>
 /// <param name="current"></param>
 /// <param name="isMonthBased"></param>
 /// <returns></returns>
 public static DateRange CreateNextRange(DateRange current, bool isMonthBased)
 {
     if (isMonthBased)
     {
         DateRangeMonth monthRange = current as DateRangeMonth;
         return CreateForNextMonth(monthRange);
     }
     DateTime startDate = current.EndDate.Date.AddDays(1);
     return CreateForXDays(current.RangeSize, startDate);
 }
Exemplo n.º 5
0
        /// <summary>
        /// Populates the data range supplied.
        /// </summary>
        /// <param name="range"></param>
        /// <param name="days"></param>
        /// <param name="start"></param>
        /// <returns></returns>
        public static DateRange CreateForXDays(DateRange range, int days, DateTime start, DateTime fetchTime)
        {
            range.StartDate = start;
            range.EndDate = start.Date.AddDays(days - 1).Add(new TimeSpan(23, 59, 0));
            range.RangeSize = (range.EndDate - range.StartDate).Days + 1;
            range.FetchTime = fetchTime;
            range.Dates = new List<DateTime>();
            range.DatesToIndex = new Dictionary<DateTime, int>();

            for (int ndx = 0; ndx < range.RangeSize; ndx++)
            {
                DateTime date = start.AddDays(ndx);
                range.Dates.Add(date);
                range.DatesToIndex.Add(date, ndx);
            }
            return range;
        }
Exemplo n.º 6
0
 /// <summary>
 /// Creates a data range for the number of days supplied.
 /// </summary>
 /// <param name="days"></param>
 /// <returns></returns>
 public static DateRange CreateForXDays(int days, DateTime start)
 {
     DateRange range = new DateRange();
     return CreateForXDays(range, days, start, DateTime.Now);
 }
Exemplo n.º 7
0
        /// <summary>
        /// Creates a data range for the year, month, day supplied.
        /// </summary>
        /// <param name="year"></param>
        /// <param name="month"></param>
        /// <param name="day"></param>
        /// <returns></returns>
        public static DateRange CreateForMonthStrict(int year, int month)
        {
            //var currentTime = new DateTime(year, month, 1);
            DateTime refDate = new DateTime(year, month, 1);
            DateRange range = new DateRange();
            int totalDays = DateHelper.GetDaysInMonth(month, year);

            // 5. Now get the dates
            CreateForXDays(range, totalDays, refDate, DateTime.Now);
            return range;
        }