Ejemplo n.º 1
0
 public void ParseNullOrEmptyValue()
 {
     DateTimeFormatter fmt = new DateTimeFormatter("d");
     Assert.AreEqual(DateTime.MinValue, fmt.Parse(null));
     Assert.IsTrue(fmt.Parse("") is DateTime);
 }
        public void ParseUsingDefaults()
        {
            DateTimeFormatter fmt = new DateTimeFormatter("d", "en-US");
            Assert.AreEqual(new DateTime(2004, 8, 14), fmt.Parse("8/14/2004"));
            Assert.AreEqual(new DateTime(1974, 8, 24), fmt.Parse("8/24/1974"));

            fmt = new DateTimeFormatter("dd-MMM-yyyy", "en-US");
            Assert.AreEqual(new DateTime(2004, 8, 14), fmt.Parse("14-Aug-2004"));
            Assert.AreEqual(new DateTime(1974, 8, 24), fmt.Parse("24-Aug-1974"));

            fmt = new DateTimeFormatter("D", CultureInfoUtils.SerbianLatinCultureName);
            Assert.AreEqual(new DateTime(2004, 8, 14), fmt.Parse("14. avgust 2004"));
            Assert.AreEqual(new DateTime(1974, 8, 24), fmt.Parse("24. avgust 1974"));

            fmt = new DateTimeFormatter("dd-MMM-yyyy", CultureInfoUtils.SerbianCyrillicCultureName);
            Assert.AreEqual(new DateTime(2004, 8, 14), fmt.Parse("14-авг-2004"));
            Assert.AreEqual(new DateTime(1974, 8, 24), fmt.Parse("24-авг-1974"));
        }
Ejemplo n.º 3
0
        public void ParseUsingDefaults()
        {
            DateTimeFormatter fmt = new DateTimeFormatter("d", "en-US");
            Assert.AreEqual(new DateTime(2004, 8, 14), fmt.Parse("8/14/2004"));
            Assert.AreEqual(new DateTime(1974, 8, 24), fmt.Parse("8/24/1974"));

            fmt = new DateTimeFormatter("dd-MMM-yyyy", "en-US");
            Assert.AreEqual(new DateTime(2004, 8, 14), fmt.Parse("14-Aug-2004"));
            Assert.AreEqual(new DateTime(1974, 8, 24), fmt.Parse("24-Aug-1974"));

            fmt = new DateTimeFormatter("D", CultureInfoUtils.SerbianLatinCultureName);

            if (CultureInfoUtils.OperatingSystemIsAfterWindows7AndBeforeWindows10Build10586 && CultureInfoUtils.ClrIsVersion4OrLater)
            {
                Assert.AreEqual(new DateTime(2004, 8, 14), fmt.Parse("14. avgust 2004."));
                Assert.AreEqual(new DateTime(1974, 8, 24), fmt.Parse("24. avgust 1974."));
            }

            else if (CultureInfoUtils.OperatingSystemIsAtLeastWindows10Build10586 && CultureInfoUtils.ClrIsVersion4OrLater)
            {
                Assert.AreEqual(new DateTime(2004, 8, 14), fmt.Parse("subota, 14. avgust 2004."));
                Assert.AreEqual(new DateTime(1974, 8, 24), fmt.Parse("subota, 24. avgust 1974."));
            }

            else
            {
                Assert.AreEqual(new DateTime(2004, 8, 14), fmt.Parse("14. avgust 2004"));
                Assert.AreEqual(new DateTime(1974, 8, 24), fmt.Parse("24. avgust 1974"));
            }

            fmt = new DateTimeFormatter("dd-MMM-yyyy", CultureInfoUtils.SerbianCyrillicCultureName);

            if (CultureInfoUtils.OperatingSystemIsAfterWindows7 && CultureInfoUtils.ClrIsVersion4OrLater)
            {
                Assert.AreEqual(new DateTime(2004, 8, 14), fmt.Parse("14-авг.-2004"));
                Assert.AreEqual(new DateTime(1974, 8, 24), fmt.Parse("24-авг.-1974"));
            }
            else
            {
                Assert.AreEqual(new DateTime(2004, 8, 14), fmt.Parse("14-авг-2004"));
                Assert.AreEqual(new DateTime(1974, 8, 24), fmt.Parse("24-авг-1974"));
            }

        }
Ejemplo n.º 4
0
 /// <summary>
 /// Obtains an instance of {@code MonthDay} from a text string using a specific formatter.
 /// <para>
 /// The text is parsed using the formatter, returning a month-day.
 ///
 /// </para>
 /// </summary>
 /// <param name="text">  the text to parse, not null </param>
 /// <param name="formatter">  the formatter to use, not null </param>
 /// <returns> the parsed month-day, not null </returns>
 /// <exception cref="DateTimeParseException"> if the text cannot be parsed </exception>
 public static MonthDay Parse(CharSequence text, DateTimeFormatter formatter)
 {
     Objects.RequireNonNull(formatter, "formatter");
     return(formatter.Parse(text, MonthDay::from));
 }