Пример #1
0
        private static bool IsValidSelectedDateFormat(object value)
        {
            DatePickerFormat format = (DatePickerFormat)value;

            return(format == DatePickerFormat.Long ||
                   format == DatePickerFormat.Short);
        }
        public void DisplaysExpectedText(CultureInfo culture, DatePickerFormat format, bool is24Hour, bool withSeconds,
                                         DateTime?selectedTime, string expectedText)
        {
            _timePicker.Language           = XmlLanguage.GetLanguage(culture.IetfLanguageTag);
            _timePicker.SelectedTimeFormat = format;
            _timePicker.Is24Hours          = is24Hour;
            _timePicker.WithSeconds        = withSeconds;
            _timePicker.SelectedTime       = selectedTime;

            Assert.Equal(expectedText, _timePicker.Text);
        }
Пример #3
0
 private static DatePickerFormat ValidateSelectedDateFormat(DatePicker dp, DatePickerFormat format)
 {
     if (IsValidSelectedDateFormat(format))
     {
         return(format);
     }
     else
     {
         throw new ArgumentOutOfRangeException(nameof(format), "DatePickerFormat value is not valid.");
     }
 }
Пример #4
0
        public void DisplaysExpectedText(CultureInfo culture, DatePickerFormat format, bool is24Hour, bool withSeconds,
                                         DateTime?selectedTime, string expectedText)
        {
            _timePicker.Language           = XmlLanguage.GetLanguage(culture.IetfLanguageTag);
            _timePicker.SelectedTimeFormat = format;
            _timePicker.Is24Hours          = is24Hour;
            _timePicker.WithSeconds        = withSeconds;
            _timePicker.SelectedTime       = selectedTime;


            string currentTestString = $"{culture.ThreeLetterISOLanguageName} {(is24Hour ? "24 Hour" : "12 Hour")} {format} format {(withSeconds ? "with seconds" : "")}";

            Assert.True(expectedText == _timePicker.Text, $"Expected '{expectedText}' but was '{_timePicker.Text}' - {currentTestString}");
        }
Пример #5
0
        public void CanParseLocalizedTimeString(CultureInfo culture, DatePickerFormat format, bool is24Hour, bool withSeconds,
                                                string timeString, DateTime?expectedTime)
        {
            _timePicker.Language           = XmlLanguage.GetLanguage(culture.IetfLanguageTag);
            _timePicker.SelectedTimeFormat = format;
            _timePicker.Is24Hours          = is24Hour;
            _timePicker.WithSeconds        = withSeconds;

            var textBox = _timePicker.FindVisualChild <TextBox>(TimePicker.TextBoxPartName);

            textBox.Text = timeString;
            textBox.RaiseEvent(new RoutedEventArgs(UIElement.LostFocusEvent));

            Assert.Equal(expectedTime, _timePicker.SelectedTime);
        }
Пример #6
0
        public void CanParseLocalizedTimeString(CultureInfo culture, DatePickerFormat format, bool is24Hour, bool withSeconds,
                                                string timeString, DateTime?expectedTime)
        {
            _timePicker.Language           = XmlLanguage.GetLanguage(culture.IetfLanguageTag);
            _timePicker.SelectedTimeFormat = format;
            _timePicker.Is24Hours          = is24Hour;
            _timePicker.WithSeconds        = withSeconds;

            var textBox = _timePicker.FindVisualChild <TextBox>(TimePicker.TextBoxPartName);

            textBox.Text = timeString;
            textBox.RaiseEvent(new RoutedEventArgs(UIElement.LostFocusEvent));

            string currentTestString = $"{culture.ThreeLetterISOLanguageName} {(is24Hour ? "24 Hour" : "12 Hour")} {format} format {(withSeconds ? "with seconds" : "")}";

            Assert.True(expectedTime == _timePicker.SelectedTime, $"Expected '{expectedTime}' but was '{_timePicker.SelectedTime}' - {currentTestString}");
        }
Пример #7
0
        // iT SHOULD RETURN NULL IF THE STRING IS NOT VALID, RETURN THE DATETIME VALUE IF IT IS VALID

        /// <summary>
        /// Input text is parsed in the correct format and changed into a DateTime object.
        /// If the text can not be parsed TextParseError Event is thrown.
        /// </summary>
        private DateTime?ParseText(string text, DatePickerFormat f)
        {
            DateTime           newSelectedDate;
            DateTimeFormatInfo dtfi = CultureInfo.CurrentCulture.DateTimeFormat;

            if (f == DatePickerFormat.Short)
            {
                try
                {
                    newSelectedDate = DateTime.ParseExact(text, dtfi.ShortDatePattern, CultureInfo.CurrentCulture);
                    return(newSelectedDate);
                }
                catch (Exception ex)
                {
                    DatePickerTextParseErrorEventArgs textParseError = new DatePickerTextParseErrorEventArgs(ex, text);
                    OnTextParseError(textParseError);

                    if (textParseError.ThrowException)
                    {
                        throw textParseError.Exception;
                    }
                }
            }
            else
            {
                Debug.Assert(f == DatePickerFormat.Long);
                try
                {
                    newSelectedDate = DateTime.ParseExact(text, dtfi.LongDatePattern, CultureInfo.CurrentCulture);
                    return(newSelectedDate);
                }
                catch (Exception ex)
                {
                    DatePickerTextParseErrorEventArgs textParseError = new DatePickerTextParseErrorEventArgs(ex, text);
                    OnTextParseError(textParseError);

                    if (textParseError.ThrowException)
                    {
                        throw textParseError.Exception;
                    }
                }
            }
            return(null);
        }
Пример #8
0
 private static bool IsValidSelectedDateFormat(DatePickerFormat value)
 {
     return(value == DatePickerFormat.Long ||
            value == DatePickerFormat.Short ||
            value == DatePickerFormat.Custom);
 }
Пример #9
0
 private string DateTimeToString(DateTime d, DatePickerFormat format) {
     var dtfi = Engine.GetDateFormat(Engine.GetCulture(this));
     switch (format) {
         case DatePickerFormat.Short:
             return string.Format(CultureInfo.CurrentCulture, d.ToString(dtfi.ShortDatePattern, dtfi));
         case DatePickerFormat.Long:
             return string.Format(CultureInfo.CurrentCulture, d.ToString(dtfi.LongDatePattern, dtfi));
     }
     return null;
 }
Пример #10
0
 /// <summary>
 /// Inherited code: Requires comment.
 /// </summary>
 /// <param name="value">Inherited code: Requires comment 1.</param>
 /// <returns>Inherited code: Requires comment 2.</returns>
 private static bool IsValidSelectedDateFormat(DatePickerFormat value)
 {
     DatePickerFormat format = (DatePickerFormat) value;
     return format == DatePickerFormat.Long
         || format == DatePickerFormat.Short;
 }
 public static T SelectedDateFormat <T>(this T source, DatePickerFormat value) where T : DatePicker
 {
     source.SelectedDateFormat = value;
     return(source);
 }
Пример #12
0
        // iT SHOULD RETURN NULL IF THE STRING IS NOT VALID, RETURN THE DATETIME VALUE IF IT IS VALID
 
        /// <summary> 
        /// Input text is parsed in the correct format and changed into a DateTime object.
        /// If the text can not be parsed TextParseError Event is thrown. 
        /// </summary>
        private DateTime? ParseText(string text, DatePickerFormat f)
        { 
            DateTime newSelectedDate;
            DateTimeFormatInfo dtfi = CultureInfo.CurrentCulture.DateTimeFormat;
 
            if (f == DatePickerFormat.Short) 
            {
                try 
                {
                    newSelectedDate = DateTime.ParseExact(text,dtfi.ShortDatePattern, CultureInfo.CurrentCulture);
                    return newSelectedDate; 
                }
                catch(Exception ex)
                { 
                    DatePickerTextParseErrorEventArgs textParseError = new DatePickerTextParseErrorEventArgs(ex, text); 
                    OnTextParseError(textParseError);
 
                    if (textParseError.ThrowException)
                    {
                        throw textParseError.Exception; 
                    }
                }
            } 
            else 
            {
                Debug.Assert(f == DatePickerFormat.Long); 
                try
                {
                    newSelectedDate = DateTime.ParseExact(text, dtfi.LongDatePattern, CultureInfo.CurrentCulture); 
                    return newSelectedDate;
                }
                catch (Exception ex) 
                { 
                    DatePickerTextParseErrorEventArgs textParseError = new DatePickerTextParseErrorEventArgs(ex, text);
                    OnTextParseError(textParseError); 

                    if (textParseError.ThrowException)
                    { 
                        throw textParseError.Exception;
                    }
                } 
            } 
            return null;
        }