Esempio n. 1
0
        public void TryParse()
        {
            bool success1 = EssentialsDate.TryParse("2019-08-17", out EssentialsDate result1);
            bool success2 = EssentialsDate.TryParse("08/17/2019", out EssentialsDate result2);

            Assert.AreEqual(true, success1);
            Assert.AreEqual(false, success2);

            Assert.AreEqual(2019, result1.Year);
            Assert.AreEqual(8, result1.Month);
            Assert.AreEqual(17, result1.Day);

            Assert.IsNull(result2);
        }
Esempio n. 2
0
        public void TryParseProvider()
        {
            CultureInfo culture = new CultureInfo("en-US");

            bool success1 = EssentialsDate.TryParse("2019-08-17", culture, DateTimeStyles.None, out EssentialsDate result1);
            bool success2 = EssentialsDate.TryParse("08/17/2019", culture, DateTimeStyles.None, out EssentialsDate result2);

            Assert.AreEqual(true, success1);
            Assert.AreEqual(true, success2);

            Assert.AreEqual(2019, result1.Year);
            Assert.AreEqual(8, result1.Month);
            Assert.AreEqual(17, result1.Day);

            Assert.AreEqual(2019, result2.Year);
            Assert.AreEqual(8, result2.Month);
            Assert.AreEqual(17, result2.Day);
        }
        public void TryParse()
        {
            bool success1 = EssentialsDate.TryParse("2019-08-17", CultureInfo.InvariantCulture, DateTimeStyles.None, out EssentialsDate result1);
            bool success2 = EssentialsDate.TryParse("08/17/2019", CultureInfo.InvariantCulture, DateTimeStyles.None, out EssentialsDate result2);
            bool success3 = EssentialsDate.TryParse("17/08/2019", CultureInfo.InvariantCulture, DateTimeStyles.None, out EssentialsDate result3);

            Assert.AreEqual(true, success1, "#1");
            Assert.AreEqual(true, success2, "#2");
            Assert.AreEqual(false, success3, "#3");

            Assert.AreEqual(2019, result1.Year);
            Assert.AreEqual(8, result1.Month);
            Assert.AreEqual(17, result1.Day);

            Assert.AreEqual(2019, result2.Year);
            Assert.AreEqual(8, result2.Month);
            Assert.AreEqual(17, result2.Day);

            Assert.IsNull(result3);
        }