Exemple #1
0
        public void TestFormat()
        {
            DateController d = new DateController();

            d.InitializeDaysOfMonth();
            string sysDateFormat = CultureInfo.CurrentCulture.DateTimeFormat.ShortDatePattern;

            /*
             * The date format is based on the system date format, so if my machine is on MDY and
             * it is sent a date using DMY the program will treat the date as MDY.
             */
            long firstDate  = d.CalculateDaysOfADate("6-8-1830");
            long secondDate = d.CalculateDaysOfADate("3-11-2018");

            //If the system date format is MDY
            if (sysDateFormat.Equals("M/d/yyyy"))
            {
                Assert.AreEqual(secondDate - firstDate, 68577);
            }
            else if (sysDateFormat.Equals("dd/MM/yyyy"))
            {
                Assert.AreEqual(secondDate - firstDate, 68755);
            }
            else
            {
                Assert.AreEqual(secondDate - firstDate, -1);
            }
        }
Exemple #2
0
        public void TestDaysDifferenceDMY()
        {
            /*
             * According to Windows Calculator the difference of days between
             * February 14, 1770
             * and
             * March 12, 2018
             * is 90606
             */
            DateController d = new DateController();

            d.InitializeDaysOfMonth();
            string sysDateFormat = CultureInfo.CurrentCulture.DateTimeFormat.ShortDatePattern;

            /*
             * The date format is based on the system date format, so if my machine is on MDY and
             * it is sent a date using DMY the program will treat the date as MDY.
             */
            long firstDate  = d.CalculateDaysOfADate("14/02/1770");
            long secondDate = d.CalculateDaysOfADate("12/03/2018");

            if (sysDateFormat.Equals("dd/MM/yyyy"))
            {
                Assert.AreEqual(secondDate - firstDate, 90606);
            }
            else if (sysDateFormat.Equals("M/d/yyyy"))
            {
                Assert.AreEqual(secondDate - firstDate, 737403);
            }
        }
Exemple #3
0
        public void TestDaysDifference()
        {
            /*
             * According to Windows Calculator the difference of days between
             * June 8, 1830
             * and
             * March 11, 2018
             * is 68577
             */
            DateController d = new DateController();

            d.InitializeDaysOfMonth();

            /*
             * The date format is based on the system date format, so if my machine is on MDY and
             * it is sent a date using DMY the program will treat the date as MDY.
             */
            long   firstDate     = d.CalculateDaysOfADate("29/02/2018");
            long   secondDate    = d.CalculateDaysOfADate("3/11/2018");
            string sysDateFormat = CultureInfo.CurrentCulture.DateTimeFormat.ShortDatePattern;

            //If the system date format is MDY
            if (sysDateFormat.Equals("M/d/yyyy"))
            {
                Assert.AreEqual(secondDate - firstDate, 68577);
            }
            else if (sysDateFormat.Equals("dd/MM/yyyy"))
            {
                Assert.AreEqual(secondDate - firstDate, 68755);
            }
            else
            {
                Assert.AreEqual(secondDate - firstDate, -1);
            }
        }
Exemple #4
0
        private void CalculateButton_Click(object sender, EventArgs e)
        {
            long finalResult;
            long daysOfFirstDate  = controller.CalculateDaysOfADate(FirstDate.Text);
            long daysOfSecondDate = controller.CalculateDaysOfADate(SecondDate.Text);

            //If the function CalculateDaysOfADate returns -1 the date is not on a valid format
            if (daysOfFirstDate.Equals(-1))
            {
                MessageBox.Show("Initial date is not on a valid format", "Date Format");
                return;
            }
            if (daysOfSecondDate.Equals(-1))
            {
                MessageBox.Show("Final date is not on a valid format", "Date Format");
                return;
            }
            //Validate (if firstDate is smaller than secondDate)
            if (daysOfFirstDate > daysOfSecondDate)
            {
                MessageBox.Show("Inital date needs to be smaller than final date", "Invalid");
            }
            else
            {
                finalResult     = (daysOfSecondDate - daysOfFirstDate) / 86400;
                ResultText.Text = finalResult.ToString() + " days";
            }
        }
Exemple #5
0
        public void TestInvalidString()
        {
            DateController d = new DateController();
            long           t = d.CalculateDaysOfADate("140589");

            Assert.AreEqual(-1, t);
        }