Пример #1
0
        private void UpdateCalendars(Windows.Globalization.Calendar calendar, DateTime oldMaxValue, DateTime oldMinValue)
        {
            this.currentCalendar = calendar.Clone();
            this.maxCalendar     = calendar.Clone();
            this.minCalendar     = calendar.Clone();

            this.maxCalendar.SetToMax();
            this.minCalendar.SetToMin();

            this.maxSupportedCalendarValue = this.maxCalendar.GetUtcDateTime();
            this.minSupportedCalendarValue = this.minCalendar.GetUtcDateTime();

            if (oldMaxValue < this.maxSupportedCalendarValue)
            {
                this.maxCalendar.SetDateTime(oldMaxValue);
            }

            if (oldMinValue > this.minSupportedCalendarValue)
            {
                this.minCalendar.SetDateTime(oldMinValue);
            }

            this.minCalendarWithStep = this.minCalendar.Clone();
            this.maxCalendarWithStep = this.maxCalendar.Clone();
            this.UpdateValuesWithStep();
        }
Пример #2
0
 internal CalendarValidator(Windows.Globalization.Calendar calendar)
 {
     this.Step     = new DateTimeOffset(1, 1, 1, 1, 1, 1, new TimeSpan(0));
     this.Calendar = calendar.Clone();
     this.Calendar.ChangeTimeZone("UTC");
     this.Initialize();
 }
Пример #3
0
        private bool FindValidHour(Windows.Globalization.Calendar calendar, int hourStep, int minuteStep, bool isMinDate, bool isMaxDate)
        {
            var clock = calendar.GetClock();

            var minHour = isMinDate && calendar.Period == this.minCalendarWithStep.Period ? this.minCalendarWithStep.ZeroBasedHour() : DateTimeHelper.GetZeroBasedHour(clock, calendar.FirstHourInThisPeriod);
            var maxHour = isMaxDate && calendar.Period == this.maxCalendarWithStep.Period ? this.maxCalendarWithStep.ZeroBasedHour() : DateTimeHelper.GetZeroBasedHour(clock, calendar.LastHourInThisPeriod);

            var firstHour   = DateTimeHelper.GetZeroBasedHour(clock, calendar.FirstHourInThisPeriod);
            var currentHour = calendar.ZeroBasedHour();

            var hourRemainder = this.GetStepRemainderForComponent(currentHour, firstHour, StepBehavior.StartFromBase, hourStep);

            currentHour -= hourRemainder;

            if (currentHour < minHour)
            {
                currentHour += hourStep;
                if (currentHour > maxHour)
                {
                    return(false);
                }
            }

            // keep the start calendar
            var startCalendar = calendar.Clone();

            startCalendar.SetZeroBasedHour(currentHour);

            while (currentHour >= minHour)
            {
                var hoursUpdate = currentHour - calendar.ZeroBasedHour();
                calendar.AddHours(hoursUpdate);
                if (hoursUpdate < 0)
                {
                    calendar.Minute = calendar.LastMinuteInThisHour;
                }

                if (this.FindValidMinute(calendar, minuteStep, isMinDate, isMaxDate))
                {
                    return(true);
                }

                currentHour -= hourStep;
            }

            calendar    = startCalendar.Clone();
            currentHour = calendar.Hour;

            while (currentHour <= maxHour)
            {
                var hoursUpdate = currentHour - calendar.ZeroBasedHour();
                calendar.AddHours(hoursUpdate);
                if (hoursUpdate > 0)
                {
                    calendar.Minute = calendar.FirstMinuteInThisHour;
                }

                if (this.FindValidMinute(calendar, minuteStep, isMinDate, isMaxDate))
                {
                    return(true);
                }

                currentHour += hourStep;
            }

            return(false);
        }
Пример #4
0
        private bool FindValidMonth(Windows.Globalization.Calendar calendar, int monthStep, int dayStep)
        {
            var minMonth = calendar.Year == this.minCalendarWithStep.Year ? this.minCalendarWithStep.Month : calendar.FirstMonthInThisYear;
            var maxMonth = calendar.Year == this.maxCalendarWithStep.Year ? this.maxCalendarWithStep.Month : calendar.LastMonthInThisYear;

            var monthRemainder = this.GetStepRemainderForComponent(calendar.Month, calendar.FirstMonthInThisYear, this.MonthStepBehavior, monthStep);

            var currentMonth = calendar.Month - monthRemainder;

            while (currentMonth < minMonth)
            {
                currentMonth += monthStep;
                if (currentMonth > maxMonth)
                {
                    return(false);
                }
            }

            // keep the start calendar
            var startCalendar = calendar.Clone();

            startCalendar.AddMonths(currentMonth - startCalendar.Month);

            while (currentMonth >= minMonth)
            {
                var monthsUpdate = currentMonth - calendar.Month;
                calendar.AddMonths(monthsUpdate);

                if (monthsUpdate < 0)
                {
                    calendar.Day = calendar.LastDayInThisMonth;
                }

                if (this.FindValidDay(calendar, dayStep))
                {
                    return(true);
                }

                currentMonth -= monthStep;
            }

            calendar     = startCalendar.Clone();
            currentMonth = calendar.Month;

            while (currentMonth <= maxMonth)
            {
                var monthsUpdate = currentMonth - calendar.Month;
                calendar.AddMonths(monthsUpdate);

                if (monthsUpdate > 0)
                {
                    calendar.Day = calendar.FirstDayInThisMonth;
                }

                if (this.FindValidDay(calendar, dayStep))
                {
                    return(true);
                }

                currentMonth += monthStep;
            }

            return(false);
        }