Пример #1
0
        /// <summary>Converts a string to a date span, using the specified
        /// context and culture information.
        /// </summary>
        /// <param name="context">
        /// An System.ComponentModel.ITypeDescriptorContext that provides a format context.
        /// </param>
        /// <param name="culture">
        /// The System.Globalization.CultureInfo to use as the current culture.
        /// </param>
        /// <param name="value">
        /// The System.Object to convert.
        /// </param>
        /// <returns>
        /// An System.Object that represents the converted value.
        /// </returns>
        /// <exception cref="NotSupportedException">
        /// The conversion cannot be performed.
        /// </exception>
        public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
        {
            var str = value as string;

            if (value is null || str != null)
            {
                return(DateSpan.Parse(str, culture));
            }
            return(base.ConvertFrom(context, culture, value));
        }
Пример #2
0
 public void Parse_InvalidInput_ThrowsFormatException()
 {
     using (new CultureInfoScope("en-GB"))
     {
         Assert.Catch <FormatException>
             (() =>
         {
             DateSpan.Parse("InvalidInput");
         },
             "Not a valid date span");
     }
 }
Пример #3
0
 public void DateRangeTests()
 {
     Assert.IsTrue(DateSpan.EntireMonth(2000, 4).Contains(new DateTime(2000, 4, 5, 13, 24, 53)));
     Assert.IsTrue(DateSpan.EntireYear(2005).Contains(DateSpan.EntireMonth(2005, 7)));
     Assert.AreEqual(new DateTime(2000, 4, 10), DateSpan.Parse("2000-4-10 to 2000-5-10").Begin);
 }