Esempio n. 1
0
        /// <summary>
        /// Determines the Ticks to be plotted for a given TimeUnit and Value.
        /// </summary>
        /// <param name="timespan">The TimeSpane for the calculation.</param>
        /// <param name="datetime">The DateTime for which the calculation is being made.</param>
        /// <param name="timeunit">The TimeUnit for the increase.</param>
        /// <param name="timevalue">The number of TimeUnits for which the increase is to be made.</param>
        /// <returns>Tick value for teh specified parameters.</returns>
        internal static long GetTickIncrease(TimeSpan timespan, DateTime datetime, TimeFrequency.TimeUnit timeunit, int timevalue)
        {
            long     ticks;
            DateTime forwardDate;

            switch (timeunit)
            {
            case TimeFrequency.TimeUnit.Year:
                // Determine the number of ticks represented by the increase
                forwardDate = datetime.AddYears(timevalue);
                ticks       = forwardDate.Ticks - datetime.Ticks;
                break;

            case TimeFrequency.TimeUnit.Month:
                // Determine the number of ticks represented by the increase
                forwardDate = datetime.AddMonths(timevalue);
                ticks       = forwardDate.Ticks - datetime.Ticks;
                break;

            case TimeFrequency.TimeUnit.Week:
            case TimeFrequency.TimeUnit.Day:
            case TimeFrequency.TimeUnit.Hour:
            case TimeFrequency.TimeUnit.Minute:
            case TimeFrequency.TimeUnit.Second:
                // Just add the normal ticks
                ticks = timespan.Ticks;
                break;

            default:
                // Just add the normal ticks
                ticks = timespan.Ticks;
                break;
            }

            return(ticks);
        }
Esempio n. 2
0
        /// <summary>
        /// Determines the Ticks to be plotted for a given TimeUnit and Value rounded to the interval.
        /// </summary>
        /// <param name="timespan">The TimeSpane for the calculation.</param>
        /// <param name="datetime">The DateTime for which the calculation is being made.</param>
        /// <param name="timeunit">The TimeUnit for the increase.</param>
        /// <param name="timevalue">The number of TimeUnits for which the increase is to be made.</param>
        /// <returns>Tick value for teh specified parameters.</returns>
        internal static long GetTickIncreaseRounded(TimeSpan timespan, DateTime datetime, TimeFrequency.TimeUnit timeunit, int timevalue)
        {
            long     ticks   = AxisHelper.GetTickIncrease(timespan, datetime, timeunit, timevalue);
            DateTime endTime = datetime.AddTicks(ticks);

            // Round Up to the nearest Interval
            double remainingTicks = endTime.Ticks % ticks;
            long   ticksToAdd     = ticks - (long)remainingTicks;

            if (endTime.Ticks + ticksToAdd < DateTime.MaxValue.Ticks)
            {
                ticks += ticksToAdd;
            }

            return(ticks);
        }