Ejemplo n.º 1
0
        public static void UpdateDate(this MauiDatePicker platformDatePicker, IDatePicker datePicker, UIDatePicker?picker)
        {
            if (picker != null && picker.Date.ToDateTime().Date != datePicker.Date.Date)
            {
                picker.SetDate(datePicker.Date.ToNSDate(), false);
            }

            platformDatePicker.Text = datePicker.Date.ToString(datePicker.Format);

            platformDatePicker.UpdateCharacterSpacing(datePicker);
        }
Ejemplo n.º 2
0
        public static void UpdateDate(this MauiDatePicker platformDatePicker, IDatePicker datePicker, UIDatePicker?picker)
        {
            if (picker != null && picker.Date.ToDateTime().Date != datePicker.Date.Date)
            {
                picker.SetDate(datePicker.Date.ToNSDate(), false);
            }

            string format = datePicker.Format ?? string.Empty;

            // Can't use VirtualView.Format because it won't display the correct format if the region and language are set differently
            if (picker != null && string.IsNullOrWhiteSpace(format) || format.Equals("d", StringComparison.OrdinalIgnoreCase))
            {
                NSDateFormatter dateFormatter = new NSDateFormatter
                {
                    TimeZone = NSTimeZone.FromGMT(0)
                };

                if (format.Equals("D", StringComparison.Ordinal) == true)
                {
                    dateFormatter.DateStyle = NSDateFormatterStyle.Long;
                    var strDate = dateFormatter.StringFor(picker?.Date);
                    platformDatePicker.Text = strDate;
                }
                else
                {
                    dateFormatter.DateStyle = NSDateFormatterStyle.Short;
                    var strDate = dateFormatter.StringFor(picker?.Date);
                    platformDatePicker.Text = strDate;
                }
            }
            else if (format.Contains('/', StringComparison.Ordinal))
            {
                platformDatePicker.Text = datePicker.Date.ToString(format, CultureInfo.InvariantCulture);
            }
            else
            {
                platformDatePicker.Text = datePicker.Date.ToString(format);
            }

            platformDatePicker.UpdateCharacterSpacing(datePicker);
        }