Ejemplo n.º 1
0
        public static double GetWidth(DateTime CurrentTime, DateTime time, TimeUnits timeUnit)
        {
            double result = TimeUnitScalar.ConvertToPixels(time, timeUnit);

            if (timeUnit == TimeUnits.Years)
            {
                if (CurrentTime.Year == time.Year)
                {
                    double DaysInYear = 365d;
                    if (DateTime.IsLeapYear(time.Year))
                    {
                        DaysInYear = 366;
                    }
                    result *= (double)(DaysInYear - time.DayOfYear + 1) / DaysInYear;
                }
            }
            else if (timeUnit == TimeUnits.Months)
            {
                if (CurrentTime.Month == time.Month)
                {
                    result *= (double)(DateTime.DaysInMonth(time.Year, time.Month) - time.Day + 1) / (double)DateTime.DaysInMonth(time.Year, time.Month);
                }
            }
            else if (timeUnit == TimeUnits.Weeks)
            {
                int daysInWeek = 7;

                int weekCurrent = GetWeekOfYear(CurrentTime);
                int weekTime    = GetWeekOfYear(time);


                if (weekTime == 52)
                {
                    daysInWeek = 7;

                    if (DateTime.IsLeapYear(time.Year))
                    {
                        daysInWeek++;
                    }

                    result *= (double)daysInWeek / 7d;
                }

                if (weekTime == 53)
                {
                    result = 0;
                }
                else if (weekCurrent == weekTime)
                {
                    daysInWeek = 7 - (CurrentTime.DayOfYear - (7 * (weekCurrent - 1))) + 2;

                    result *= (double)daysInWeek / 7d;
                }
            }


            return(result);
        }
Ejemplo n.º 2
0
        public static double GetPosition(DateTime CurrentTime, DateTime TargetTime)
        {
            double result = 0d;

            TimeSpan ts = TargetTime.Date - CurrentTime.Date;

            double UnitWidth = TimeUnitScalar.ConvertToPixels(TargetTime, TimeUnits.Ticks);

            result = (UnitWidth * ts.Ticks);

            return(result);
        }