コード例 #1
0
        public void ParseNullOrEmptyValue()
        {
            DateTimeFormatter fmt = new DateTimeFormatter("d");

            Assert.AreEqual(DateTime.MinValue, fmt.Parse(null));
            Assert.IsTrue(fmt.Parse("") is DateTime);
        }
コード例 #2
0
        public void FormatUsingDefaults()
        {
            DateTimeFormatter fmt = new DateTimeFormatter("d", "en-US");

            Assert.AreEqual("8/14/2004", fmt.Format(new DateTime(2004, 8, 14)));
            Assert.AreEqual("8/24/1974", fmt.Format(new DateTime(1974, 8, 24)));

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

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

            Console.WriteLine("Steve:  " + Environment.Version);


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

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

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

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

            if (CultureInfoUtils.OperatingSystemIsAfterWindows7 && CultureInfoUtils.ClrIsVersion4OrLater)
            {
                Assert.AreEqual("14-авг.-2004", fmt.Format(new DateTime(2004, 8, 14)));
                Assert.AreEqual("24-авг.-1974", fmt.Format(new DateTime(1974, 8, 24)));
            }
            else
            {
                Assert.AreEqual("14-авг-2004", fmt.Format(new DateTime(2004, 8, 14)));
                Assert.AreEqual("24-авг-1974", fmt.Format(new DateTime(1974, 8, 24)));
            }
        }
コード例 #3
0
        public void FormatNonDate()
        {
            DateTimeFormatter fmt = new DateTimeFormatter("d");

            Assert.Throws <ArgumentException>(() => fmt.Format("not a date"));
        }
コード例 #4
0
        public void FormatNullValue()
        {
            DateTimeFormatter fmt = new DateTimeFormatter("d");

            Assert.Throws <ArgumentNullException>(() => fmt.Format(null));
        }