Ejemplo n.º 1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DateTimeList"/> class.
 /// </summary>
 public DateTimeList()
 {
     this.DefaultStyleKey     = typeof(DateTimeList);
     this.componentType       = DateTimeComponentType.Day;
     this.currentListUtcValue = DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Utc);
     this.IsExpanded          = false;
 }
Ejemplo n.º 2
0
        private int GetLogicalIndexFromComponentValueWithoutStepApplied(DateTimeComponentType type)
        {
            var calendar = this.owner.calendarValidator.Calendar;

            calendar.SetDateTime(this.currentListUtcValue);

            switch (type)
            {
            case DateTimeComponentType.Day:
                return(calendar.Day - calendar.FirstDayInThisMonth + 1);

            case DateTimeComponentType.Month:
                return(calendar.Month - calendar.FirstMonthInThisYear + 1);

            case DateTimeComponentType.Year:
                return(calendar.Year - calendar.FirstYearInThisEra + 1);

            case DateTimeComponentType.Hour:
                return((calendar.NumberOfPeriodsInThisDay == 2 && calendar.Hour == 12) ? 0 : calendar.Hour);

            case DateTimeComponentType.Minute:
                return(calendar.Minute);

            case DateTimeComponentType.AMPM:
                // 0 if AM, 1 if PM
                return(calendar.Period - 1);

            default:
                return(0);
            }
        }
Ejemplo n.º 3
0
        private int GetStepForComponentType(DateTimeComponentType componentType)
        {
            switch (componentType)
            {
            case DateTimeComponentType.Day:
                return(this.Step.Day);

            case DateTimeComponentType.Month:
                return(this.Step.Month);

            case DateTimeComponentType.Year:
                return(this.Step.Year);

            case DateTimeComponentType.Hour:
                return(this.Step.Hour == 0 ? 1 : this.Step.Hour);

            case DateTimeComponentType.Minute:
                return(this.Step.Minute == 0 ? 1 : this.Step.Minute);

            case DateTimeComponentType.Second:
                return(this.Step.Second == 0 ? 1 : this.Step.Second);

            default:
                return(1);
            }
        }
Ejemplo n.º 4
0
        internal override StepBehavior GetBehaviorForComponent(DateTimeComponentType dateTimeComponentType)
        {
            switch (dateTimeComponentType)
            {
            case DateTimeComponentType.Day: return(this.DayStepBehavior);

            case DateTimeComponentType.Month: return(this.MonthStepBehavior);

            case DateTimeComponentType.Year: return(this.YearStepBehavior);

            default: return(StepBehavior.Multiples);
            }
        }
Ejemplo n.º 5
0
        private int GetIndexFromCurrentValueForComponentType(DateTimeComponentType type)
        {
            int index          = 0;
            int componentValue = this.GetLogicalIndexFromComponentValueWithoutStepApplied(type);
            var stepBehavior   = this.owner.GetBehaviorForComponent(this.componentType);

            switch (this.componentType)
            {
            case DateTimeComponentType.Day:
            case DateTimeComponentType.Month:
            case DateTimeComponentType.Year:

                if (this.Step == 1)
                {
                    return(componentValue - 1);
                }

                if (stepBehavior == StepBehavior.Multiples)
                {
                    index = Math.Max((componentValue / this.Step) - 1, 0);
                }
                else
                {
                    index = Math.Min(componentValue / this.Step, this.GetLogicalCount() - 1);
                }

                break;

            case DateTimeComponentType.Hour:
                index = componentValue / this.Step;
                break;

            case DateTimeComponentType.Minute:
                index = componentValue / this.Step;
                break;

            case DateTimeComponentType.AMPM:
                // 0 if AM, 1 if PM
                return(componentValue);
            }

            return(index);
        }
Ejemplo n.º 6
0
 internal abstract StepBehavior GetBehaviorForComponent(DateTimeComponentType dateTimeComponentType);
Ejemplo n.º 7
0
        internal DateTime CoerceDateTimeWithStep(int logicalIndexBasedOnBehavior, DateTimeComponentType componentType, DateTime value)
        {
            if (this.minCalendarWithStep.CompareDateTime(value) == 1)
            {
                value = this.minCalendarWithStep.GetUtcDateTime();
            }
            else if (this.maxCalendarWithStep.CompareDateTime(value) == -1)
            {
                value = this.maxCalendarWithStep.GetUtcDateTime();
            }

            this.Calendar.SetDateTime(value);
            switch (componentType)
            {
            case DateTimeComponentType.Day:
                logicalIndexBasedOnBehavior += this.Calendar.FirstDayInThisMonth - 1;
                var day = Math.Min(this.Calendar.NumberOfDaysInThisMonth, logicalIndexBasedOnBehavior);
                this.Calendar.AddDays(day - this.Calendar.Day);
                return(this.Calendar.GetUtcDateTime());

            case DateTimeComponentType.Month:
                logicalIndexBasedOnBehavior += this.Calendar.FirstMonthInThisYear - 1;
                var month = Math.Min(this.Calendar.NumberOfMonthsInThisYear, logicalIndexBasedOnBehavior);
                this.Calendar.AddMonths(month - this.Calendar.Month);
                if (this.Calendar.Year == this.minCalendarWithStep.Year &&
                    this.Calendar.Month == this.minCalendarWithStep.Month &&
                    this.Calendar.Day < this.minCalendarWithStep.Day)
                {
                    this.Calendar.Day = this.minCalendarWithStep.Day;
                }
                if (this.Calendar.Year == this.maxCalendarWithStep.Year &&
                    this.Calendar.Month == this.maxCalendarWithStep.Month &&
                    this.Calendar.Day > this.maxCalendarWithStep.Day)
                {
                    this.Calendar.Day = this.maxCalendarWithStep.Day;
                }
                return(this.Calendar.GetUtcDateTime());

            case DateTimeComponentType.Year:
                logicalIndexBasedOnBehavior += this.Calendar.FirstYearInThisEra - 1;
                var year = logicalIndexBasedOnBehavior;
                this.Calendar.AddYears(year - this.Calendar.Year);
                if ((this.Calendar.Year == this.minCalendarWithStep.Year) &&
                    ((this.Calendar.Month < this.minCalendarWithStep.Month) ||
                     (this.Calendar.Month == this.minCalendarWithStep.Month &&
                      this.Calendar.Day < this.minCalendarWithStep.Day)))
                {
                    return(this.minCalendarWithStep.GetUtcDateTime());
                }
                if ((this.Calendar.Year == this.maxCalendarWithStep.Year) &&
                    ((this.Calendar.Month > this.maxCalendarWithStep.Month) ||
                     (this.Calendar.Month == this.maxCalendarWithStep.Month &&
                      this.Calendar.Day > this.maxCalendarWithStep.Day)))
                {
                    return(this.maxCalendarWithStep.GetUtcDateTime());
                }
                return(this.Calendar.GetUtcDateTime());

            case DateTimeComponentType.Hour:
                int calendarHour = this.Calendar.ZeroBasedHour();
                int hour         = logicalIndexBasedOnBehavior;
                this.Calendar.AddHours(hour - calendarHour);
                var date      = this.Calendar.GetUtcDateTime().Date;
                var isMinDate = date == this.minCalendarWithStep.GetUtcDateTime().Date;
                var isMaxDate = date == this.maxCalendarWithStep.GetUtcDateTime().Date;
                if (isMinDate && this.Calendar.Hour == this.minCalendarWithStep.Hour && this.Calendar.Minute < this.minCalendarWithStep.Minute)
                {
                    return(this.minCalendarWithStep.GetUtcDateTime());
                }
                if (isMaxDate && this.Calendar.Hour == this.maxCalendarWithStep.Hour && this.Calendar.Minute > this.maxCalendarWithStep.Minute)
                {
                    return(this.maxCalendarWithStep.GetUtcDateTime());
                }
                return(this.Calendar.GetUtcDateTime());

            case DateTimeComponentType.Minute:
                int minute = logicalIndexBasedOnBehavior;
                this.Calendar.AddMinutes(minute - this.Calendar.Minute);
                return(this.Calendar.GetUtcDateTime());

            case DateTimeComponentType.AMPM:
                int period = logicalIndexBasedOnBehavior + this.Calendar.FirstPeriodInThisDay;
                this.Calendar.AddPeriods(period - this.Calendar.Period);
                return(this.Calendar.GetUtcDateTime());
            }

            return(value);
        }
Ejemplo n.º 8
0
 internal override StepBehavior GetBehaviorForComponent(DateTimeComponentType dateTimeComponentType)
 {
     return(StepBehavior.Multiples);
 }