Ejemplo n.º 1
0
        /// <summary>
        /// Determines the next date
        /// </summary>
        public static (int, int, int) IncreaseDate(string value_day, string value_month, string value_year, string count_day)
        {
            int real_day_month_next = 0;
            int leftover_days       = 0;
            int last_day_month      = 0;

            bool isNumberDay       = int.TryParse(value_day, out int day);
            bool isNumberMonth     = int.TryParse(value_month, out int month);
            bool isNumberYear      = int.TryParse(value_year, out int year);
            bool isNumberCountDays = int.TryParse(count_day, out int amount_days);

            bool isDate = AuxiliaryMethods.IsCorrectDate(isNumberDay, isNumberMonth, isNumberYear, day, month, year);

            //Validating date
            if (!isDate || !isNumberCountDays)
            {
                throw new ArgumentException("Error, incorrect date");
            }

            last_day_month = AuxiliaryMethods.LastDayMonthNext(month - 1, year);
            //Difference between the total days of the month and the number of days
            leftover_days = last_day_month - day;

            if (leftover_days >= amount_days)
            {
                day = day + amount_days;
                return(day, month, year);
            }
            real_day_month_next = amount_days - leftover_days;
            last_day_month      = AuxiliaryMethods.LastDayMonthNext(month, year);

            while (true)
            {
                if (real_day_month_next > last_day_month)
                {
                    if (month == 12)
                    {
                        month = 0;
                        year++;
                    }
                    month++;
                    real_day_month_next = real_day_month_next - last_day_month;
                    last_day_month      = AuxiliaryMethods.LastDayMonthNext(month, year);
                }
                else
                {
                    if (month == 12)
                    {
                        month = 1;
                        year++;
                        return(real_day_month_next, month, year);
                    }
                    else
                    {
                        month++;
                        return(real_day_month_next, month, year);
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public static int DifferentTwoDates(string value_day, string value_month, string value_year, string value_day2, string value_month2, string value_year2)
        {
            int util_day          = 0;
            int util_month        = 0;
            int util_year         = 0;
            int last_day_month    = 0;
            int real_day_year     = 0;
            int cont_year_leap    = 0;
            int cont_year_no_leap = 0;

            bool isNumberDay   = int.TryParse(value_day, out int day);
            bool isNumberMonth = int.TryParse(value_month, out int month);
            bool isNumberYear  = int.TryParse(value_year, out int year);

            bool isNumberDay2   = int.TryParse(value_day2, out int second_day);
            bool isNumberMonth2 = int.TryParse(value_month2, out int second_month);
            bool isNumberYear2  = int.TryParse(value_year2, out int second_year);

            bool isDate  = AuxiliaryMethods.IsCorrectDate(isNumberDay, isNumberMonth, isNumberYear, day, month, year);
            bool isDate2 = AuxiliaryMethods.IsCorrectDate(isNumberDay2, isNumberMonth2, isNumberYear2, second_day, second_month, second_year);

            //Validating date
            if (!isDate || !isDate2)
            {
                throw new ArgumentException("Error, incorrect date");
            }

            if ((second_day <= day && second_month == month && second_year == year) || (second_year < year) || second_month < month && second_year == year)
            {   //In case the initial date is greater than the final date, it is reversed.
                util_day     = day;
                util_month   = month;
                util_year    = year;
                day          = second_day;
                month        = second_month;
                year         = second_year;
                second_day   = util_day;
                second_month = util_month;
                second_year  = util_year;
            }

            int temp_year         = year + 1;
            int first_latest_year = year;

            if (year == second_year && month == second_month)
            {
                real_day_year = second_day - day;
                return(real_day_year);
            }

            last_day_month = AuxiliaryMethods.LastDayMonthNext(month - 1, year);
            real_day_year  = last_day_month - day;

            while (temp_year < second_year)
            {
                bool isLeapYear = AuxiliaryMethods.IsLeapYear(temp_year);

                if (isLeapYear)
                {
                    temp_year++;
                    cont_year_leap++;
                }
                else
                {
                    temp_year++;
                    cont_year_no_leap++;
                }
            }

            real_day_year = real_day_year + (cont_year_no_leap * 365 + cont_year_leap * 366);

            while (true)
            {
                if (month != 12)
                {
                    last_day_month = AuxiliaryMethods.LastDayMonthNext(month, year);
                    real_day_year  = real_day_year + last_day_month;
                    month++;
                }
                if (month == 12 && first_latest_year == year)
                {
                    month             = 1;
                    year              = second_year;
                    first_latest_year = year;
                }
                if ((month == second_month - 1 || month == second_month) && first_latest_year == second_year)
                {
                    real_day_year = real_day_year + second_day;
                    return(real_day_year);
                }
                else if (month == 1 && first_latest_year == second_year)
                {
                    last_day_month = AuxiliaryMethods.LastDayMonthNext(month - 1, year);
                    real_day_year  = real_day_year + last_day_month;
                }
            }
        }