public static long[] GetDataTimeExtent(DateTime min, DateTime max, double m, out DateTimeStep dateTimeStep)
        {
            double span   = max.Ticks - min.Ticks;
            double target = span / m;

            int    count         = 0;
            int    i             = _dateTimeSteps.Count - 1;
            double lastStepValue = 0;

            foreach (var step in _dateTimeSteps)
            {
                if (target > lastStepValue && target < step.DateTimeStepMaxValue)
                {
                    i = count;
                    i = Math.Max(0, i - 1);
                    break;
                }
                lastStepValue = step.DateTimeStepMaxValue;
                count++;
            }

            long[] ret = new long[2];
            ret[0]       = RoundDateTimeTo(min, _dateTimeSteps[i]).Ticks;
            ret[1]       = AddToDateTime(RoundDateTimeTo(AddToDateTime(max, _dateTimeSteps[i]), _dateTimeSteps[i]), _dateTimeSteps[i]).Ticks;
            dateTimeStep = new DateTimeStep()
            {
                DateTimeStepGranularity = _dateTimeSteps[i].DateTimeStepGranularity,
                DateTimeStepMaxValue    = _dateTimeSteps[i].DateTimeStepMaxValue,
                DateTimeStepValue       = _dateTimeSteps[i].DateTimeStepValue
            };
            return(ret);
        }
 public static DateTime AddToDateTime(DateTime dt, DateTimeStep dateTimeStep)
 {
     if (dateTimeStep.DateTimeStepGranularity == DateTimeStepGranularity.Second)
     {
         return(new DateTime(dt.Ticks + TimeSpan.FromSeconds(dateTimeStep.DateTimeStepValue).Ticks));
     }
     else if (dateTimeStep.DateTimeStepGranularity == DateTimeStepGranularity.Minute)
     {
         return(new DateTime(dt.Ticks + TimeSpan.FromMinutes(dateTimeStep.DateTimeStepValue).Ticks));
     }
     else if (dateTimeStep.DateTimeStepGranularity == DateTimeStepGranularity.Hour)
     {
         return(new DateTime(dt.Ticks + TimeSpan.FromHours(dateTimeStep.DateTimeStepValue).Ticks));
     }
     else if (dateTimeStep.DateTimeStepGranularity == DateTimeStepGranularity.Day)
     {
         return(new DateTime(dt.Ticks + TimeSpan.FromDays(dateTimeStep.DateTimeStepValue).Ticks));
     }
     else if (dateTimeStep.DateTimeStepGranularity == DateTimeStepGranularity.Month)
     {
         return(dt.AddMonths((int)dateTimeStep.DateTimeStepValue));
     }
     else if (dateTimeStep.DateTimeStepGranularity == DateTimeStepGranularity.Year)
     {
         return(dt.AddYears((int)dateTimeStep.DateTimeStepValue));
     }
     else
     {
         return(DateTime.Now);
     }
 }
 public static string GetLabel(DateTime dt, DateTimeStep dateTimeStep)
 {
     //MM/dd/yyyy HH:mm:ss
     if (dateTimeStep.DateTimeStepGranularity == DateTimeStepGranularity.Second ||
         dateTimeStep.DateTimeStepGranularity == DateTimeStepGranularity.Minute)
     {
         return(dt.ToString("mm:ss"));
     }
     else if (dateTimeStep.DateTimeStepGranularity == DateTimeStepGranularity.Hour)
     {
         return(dt.ToString("HH:mm"));
     }
     else if (dateTimeStep.DateTimeStepGranularity == DateTimeStepGranularity.Day)
     {
         return(dt.ToString("MM/dd/yyyy"));
     }
     else if (dateTimeStep.DateTimeStepGranularity == DateTimeStepGranularity.Month)
     {
         return(dt.ToString("MM/yyyy"));
     }
     else if (dateTimeStep.DateTimeStepGranularity == DateTimeStepGranularity.Year)
     {
         return(dt.ToString("yyyy"));
     }
     return("");
 }
 public static DateTime RemoveFromDateTime(DateTime dt, DateTimeStep dateTimeStep)
 {
     return(AddToDateTime(dt, new DateTimeStep()
     {
         DateTimeStepGranularity = dateTimeStep.DateTimeStepGranularity,
         DateTimeStepValue = -dateTimeStep.DateTimeStepValue
     }));
 }
        public static DateTime IncludeDateTime(DateTime from, DateTime to, DateTimeStep dateTimeStep, bool inclusive, out int stepsTaken)
        {
            stepsTaken = 0;
            DateTime min = from < to ? from : to;
            DateTime max = from > to ? from : to;

            DateTime current = new DateTime(min.Ticks);

            if (inclusive)
            {
                while (current <= max)
                {
                    if (from <= to)
                    {
                        current = AddToDateTime(current, dateTimeStep);
                    }
                    else
                    {
                        current = RemoveFromDateTime(current, dateTimeStep);
                    }
                    stepsTaken++;
                }
            }
            else
            {
                while (current < max)
                {
                    if (from < to)
                    {
                        current = AddToDateTime(current, dateTimeStep);
                    }
                    else
                    {
                        current = RemoveFromDateTime(current, dateTimeStep);
                    }
                    stepsTaken++;
                }
            }
            return(current);
        }
 public static DateTime RoundDateTimeTo(DateTime dt, DateTimeStep dateTimeStep)
 {
     if (dateTimeStep.DateTimeStepGranularity == DateTimeStepGranularity.Second)
     {
         return(new DateTime((long)Math.Floor((double)(dt.Ticks / TimeSpan.FromSeconds(dateTimeStep.DateTimeStepValue).Ticks)) * TimeSpan.FromSeconds(dateTimeStep.DateTimeStepValue).Ticks));
     }
     else if (dateTimeStep.DateTimeStepGranularity == DateTimeStepGranularity.Minute)
     {
         return(new DateTime((long)Math.Floor((double)(dt.Ticks / TimeSpan.FromMinutes(dateTimeStep.DateTimeStepValue).Ticks)) * TimeSpan.FromMinutes(dateTimeStep.DateTimeStepValue).Ticks));
     }
     else if (dateTimeStep.DateTimeStepGranularity == DateTimeStepGranularity.Hour)
     {
         return(new DateTime((long)Math.Floor((double)(dt.Ticks / TimeSpan.FromHours(dateTimeStep.DateTimeStepValue).Ticks)) * TimeSpan.FromHours(dateTimeStep.DateTimeStepValue).Ticks));
     }
     else if (dateTimeStep.DateTimeStepGranularity == DateTimeStepGranularity.Day)
     {
         return(new DateTime((long)Math.Floor((double)(dt.Ticks / TimeSpan.FromDays(dateTimeStep.DateTimeStepValue).Ticks)) * TimeSpan.FromDays(dateTimeStep.DateTimeStepValue).Ticks));
     }
     else if (dateTimeStep.DateTimeStepGranularity == DateTimeStepGranularity.Month)
     {
         if (dateTimeStep.DateTimeStepValue == 1)
         {
             return(new DateTime(dt.Year, dt.Month, 1));
         }
         else
         {
             var ttt = (int)(Math.Floor((dt.Month - 1) / dateTimeStep.DateTimeStepValue) * dateTimeStep.DateTimeStepValue) + 1;
             return(new DateTime(dt.Year, (int)(Math.Floor((dt.Month - 1) / dateTimeStep.DateTimeStepValue) * dateTimeStep.DateTimeStepValue) + 1, 1));
         }
     }
     else if (dateTimeStep.DateTimeStepGranularity == DateTimeStepGranularity.Year)
     {
         return(new DateTime(dt.Year, 1, 1));
     }
     else
     {
         return(DateTime.Now);
     }
 }
 public static DateTime RoundDateTimeTo(long ticks, DateTimeStep dateTimeStep)
 {
     return(RoundDateTimeTo(new DateTime(ticks), dateTimeStep));
 }
 public static long[] GetDataTimeExtent(double min, double max, double m, out DateTimeStep dateTimeStep)
 {
     return(GetDataTimeExtent(new DateTime((long)min), new DateTime((long)max), m, out dateTimeStep));
 }
 public static string GetLabel(double ticks, DateTimeStep dateTimeStep)
 {
     return(GetLabel(new DateTime((long)ticks), dateTimeStep));
 }
 public static DateTime AddToDateTime(double ticks, DateTimeStep dateTimeStep)
 {
     return(AddToDateTime(new DateTime((long)ticks), dateTimeStep));
 }
 public static DateTime RemoveFromDateTime(double ticks, DateTimeStep dateTimeStep)
 {
     return(RemoveFromDateTime(new DateTime((long)ticks), dateTimeStep));
 }
 public static DateTime IncludeDateTime(double from, double to, DateTimeStep dateTimeStep, bool inclusive, out int stepsTaken)
 {
     return(IncludeDateTime(new DateTime((long)from), new DateTime((long)to), dateTimeStep, inclusive, out stepsTaken));
 }