Esempio n. 1
0
        protected internal override void Open()
        {
            var date = Date;

            // If we're setting the date to the null sentinel value,
            // we'll instead set it to the current date for the purposes
            // of where to place the user's position in the looping selectors.
            if (date.Ticks == DatePicker.DEFAULT_DATE_TICKS)
            {
                var temp     = new Windows.Globalization.Calendar();
                var calendar = new Windows.Globalization.Calendar(
                    temp.Languages,
                    CalendarIdentifier,
                    temp.GetClock());
                calendar.SetToNow();
                date = calendar.GetDateTime();
            }

            // Note: Month needs to be -1 since on Android months go from 0-11
            // http://developer.android.com/reference/android/app/DatePickerDialog.OnDateSetListener.html#onDateSet(android.widget.DatePicker, int, int, int)
            _dialog = new DatePickerDialog(
                ContextHelper.Current,
                OnDateSet,
                date.Year,
                date.Month - 1,
                date.Day
                );

            //Removes title that is unnecessary as it is a duplicate -> http://stackoverflow.com/questions/33486643/remove-title-from-datepickerdialog
            _dialog.SetTitle("");

            var minYearCalendar = Calendar.Instance;

            minYearCalendar.Set(MinYear.Year, MinYear.Month - 1, MinYear.Day, MinYear.Hour, MinYear.Minute, MinYear.Second);
            _dialog.DatePicker.MinDate = minYearCalendar.TimeInMillis;

            var maxYearCalendar = Calendar.Instance;

            maxYearCalendar.Set(MaxYear.Year, MaxYear.Month - 1, MaxYear.Day, MaxYear.Hour, MaxYear.Minute, MaxYear.Second);
            _dialog.DatePicker.MaxDate = maxYearCalendar.TimeInMillis;

            _dialog.DismissEvent += OnDismiss;
            _dialog.Show();
        }
Esempio n. 2
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);
        }