Example #1
0
        public static DateTimeSequence CalculateMilliseconds(Range <DateTime> range, int?interval, int?intervalOffset, int maxCount)
        {
            DateTime        dateTime        = new DateTime(range.Minimum.Year, range.Minimum.Month, range.Minimum.Day, range.Minimum.Hour, range.Minimum.Minute, range.Minimum.Second);
            NumericSequence numericSequence = NumericSequence.CalculateUnits((int)Math.Floor(range.Minimum.Subtract(dateTime).TotalMilliseconds), (int)Math.Ceiling(range.Maximum.Subtract(dateTime).TotalMilliseconds), interval, intervalOffset, new int[10]
            {
                1,
                2,
                5,
                10,
                20,
                50,
                100,
                200,
                500,
                1000
            }, maxCount);
            DateTimeSequence dateTimeSequence = new DateTimeSequence(DateTimeScaleUnit.Milliseconds);

            try
            {
                foreach (DoubleR10 doubleR10 in numericSequence)
                {
                    double num = (double)doubleR10;
                    dateTimeSequence.Add(dateTime.AddMilliseconds(num));
                }
            }
            catch (ArgumentOutOfRangeException ex)
            {
            }
            dateTimeSequence.Interval       = numericSequence.Interval;
            dateTimeSequence.IntervalOffset = numericSequence.IntervalOffset;
            return(dateTimeSequence);
        }
Example #2
0
        public static DateTimeSequence CalculateHours(Range <DateTime> range, int?interval, int?intervalOffset, int maxCount)
        {
            DateTime        dateTime        = new DateTime(range.Minimum.Year, range.Minimum.Month, range.Minimum.Day, 0, 0, 0);
            NumericSequence numericSequence = NumericSequence.CalculateUnits((int)Math.Floor(range.Minimum.Subtract(dateTime).TotalHours), (int)Math.Ceiling(range.Maximum.Subtract(dateTime).TotalHours), interval, intervalOffset, new int[6]
            {
                1,
                2,
                3,
                6,
                12,
                24
            }, maxCount);
            DateTimeSequence dateTimeSequence = new DateTimeSequence(DateTimeScaleUnit.Hours);

            try
            {
                foreach (DoubleR10 doubleR10 in numericSequence)
                {
                    int      num  = (int)doubleR10;
                    DateTime date = dateTime.AddHours((double)num);
                    dateTimeSequence.Add(date);
                }
            }
            catch (ArgumentOutOfRangeException ex)
            {
            }
            dateTimeSequence.Interval       = numericSequence.Interval;
            dateTimeSequence.IntervalOffset = numericSequence.IntervalOffset;
            return(dateTimeSequence);
        }
Example #3
0
        public static DateTimeSequence CalculateMonths(Range <DateTime> range, int?interval, int?intervalOffset, int maxCount)
        {
            DateTime        dateTime        = new DateTime(range.Minimum.Year, 1, 1);
            NumericSequence numericSequence = NumericSequence.CalculateUnits(range.Minimum.Month - 1, (range.Maximum.Year - dateTime.Year) * 12 + range.Maximum.Month - 1, interval, intervalOffset, new int[5]
            {
                1,
                2,
                3,
                6,
                12
            }, maxCount);
            DateTimeSequence dateTimeSequence = new DateTimeSequence(DateTimeScaleUnit.Months);

            try
            {
                foreach (DoubleR10 doubleR10 in numericSequence)
                {
                    int      months = (int)doubleR10;
                    DateTime date   = dateTime.AddMonths(months);
                    dateTimeSequence.Add(date);
                }
            }
            catch (ArgumentOutOfRangeException ex)
            {
            }
            dateTimeSequence.Interval       = numericSequence.Interval;
            dateTimeSequence.IntervalOffset = numericSequence.IntervalOffset;
            return(dateTimeSequence);
        }
Example #4
0
        public static DateTimeSequence CalculateYears(Range <DateTime> range, int?interval, int?intervalOffset, int maxCount)
        {
            NumericSequence numericSequence = NumericSequence.CalculateUnits(range.Minimum.Year, range.Maximum.Year, interval, intervalOffset, new int[10]
            {
                1,
                2,
                5,
                10,
                20,
                50,
                100,
                200,
                500,
                1000
            }, maxCount);
            DateTimeSequence dateTimeSequence = new DateTimeSequence(DateTimeScaleUnit.Years);

            try
            {
                foreach (DoubleR10 doubleR10 in numericSequence)
                {
                    int year = (int)doubleR10;
                    if (year > 0 && year < 10000)
                    {
                        dateTimeSequence.Add(new DateTime(year, 1, 1));
                    }
                }
            }
            catch (ArgumentOutOfRangeException ex)
            {
            }
            dateTimeSequence.Interval       = numericSequence.Interval;
            dateTimeSequence.IntervalOffset = numericSequence.IntervalOffset;
            return(dateTimeSequence);
        }
Example #5
0
        public static DateTimeSequence CalculateWeeks(Range <DateTime> range, int?interval, int?intervalOffset, int maxCount, DayOfWeek firstDayOfWeek)
        {
            DateTime dateTime = new DateTime(range.Minimum.Year, range.Minimum.Month, range.Minimum.Day);

            while (dateTime.DayOfWeek != firstDayOfWeek)
            {
                dateTime = dateTime.AddDays(-1.0);
            }
            int num1            = (int)Math.Floor(range.Minimum.Subtract(dateTime).TotalDays);
            int num2            = (int)Math.Ceiling(range.Maximum.Subtract(dateTime).TotalDays);
            int min             = num1;
            int max             = num2;
            int?nullable        = interval;
            int?interval1       = nullable.HasValue ? new int?(nullable.GetValueOrDefault() * 7) : new int?();
            int?intervalOffset1 = intervalOffset;

            int[] steps = new int[2]
            {
                7,
                14
            };
            int              maxCount1        = maxCount;
            NumericSequence  numericSequence  = NumericSequence.CalculateUnits(min, max, interval1, intervalOffset1, steps, maxCount1);
            DateTimeSequence dateTimeSequence = new DateTimeSequence(DateTimeScaleUnit.Weeks);

            try
            {
                foreach (DoubleR10 doubleR10 in numericSequence)
                {
                    int      num3 = (int)doubleR10;
                    DateTime date = dateTime.AddDays((double)num3);
                    dateTimeSequence.Add(date);
                }
            }
            catch (ArgumentOutOfRangeException ex)
            {
            }
            dateTimeSequence.Interval       = numericSequence.Interval / (DoubleR10)7;
            dateTimeSequence.IntervalOffset = numericSequence.IntervalOffset / (DoubleR10)7;
            return(dateTimeSequence);
        }