Ejemplo n.º 1
0
        public void DateDiffTest()
        {
            DateTime dateNow     = DateTime.Now;
            DateTime testYear    = dateNow.AddYears(1);
            DateTime testMonth   = dateNow.AddMonths(1);
            DateTime testDay     = dateNow.AddDays(1);
            DateTime testHour    = dateNow.AddHours(1);
            DateTime testMinute  = dateNow.AddMinutes(1);
            DateTime testSeconds = dateNow.AddSeconds(1);

            string result;

            result = _extension.DateDiff("Y", dateNow, testYear);
            Assert.AreEqual("1", result);

            result = _extension.DateDiff("MM", dateNow, testMonth);
            Assert.AreEqual("1", result);

            result = _extension.DateDiff("D", dateNow, testDay);
            Assert.AreEqual("1", result);

            result = _extension.DateDiff("H", dateNow, testHour);
            Assert.AreEqual("1", result);

            result = _extension.DateDiff("M", dateNow, testHour);
            Assert.AreEqual("60", result);

            result = _extension.DateDiff("S", dateNow, testHour);
            Assert.AreEqual("3600", result);

            result = _extension.DateDiff("M", dateNow, testMinute);
            Assert.AreEqual("1", result);

            result = _extension.DateDiff("S", dateNow, testMinute);
            Assert.AreEqual("60", result);

            result = _extension.DateDiff("S", dateNow, testSeconds);
            Assert.AreEqual("1", result);
        }
        public void DateDiffTest()
        {
            DateTime dateNow     = DateTime.Now;
            DateTime testYear    = dateNow.AddYears(1);
            DateTime testMonth   = dateNow.AddMonths(1);
            DateTime testDay     = dateNow.AddDays(1);
            DateTime testHour    = dateNow.AddHours(1);
            DateTime testMinute  = dateNow.AddMinutes(1);
            DateTime testSeconds = dateNow.AddSeconds(1);

            long result;

            result = _extension.DateDiff("Y", dateNow, testYear);
            Assert.IsTrue(result == 1);

            result = _extension.DateDiff("MM", dateNow, testMonth);
            Assert.IsTrue(result == 1);

            result = _extension.DateDiff("D", dateNow, testDay);
            Assert.IsTrue(result == 1);

            result = _extension.DateDiff("H", dateNow, testHour);
            Assert.IsTrue(result == 1);

            result = _extension.DateDiff("M", dateNow, testHour);
            Assert.IsTrue(result == 60);

            result = _extension.DateDiff("S", dateNow, testHour);
            Assert.IsTrue(result == 3600);

            result = _extension.DateDiff("M", dateNow, testMinute);
            Assert.IsTrue(result == 1);

            result = _extension.DateDiff("S", dateNow, testMinute);
            Assert.IsTrue(result == 60);

            result = _extension.DateDiff("S", dateNow, testSeconds);
            Assert.IsTrue(result == 1);
        }