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); 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")); } }