//Расчет периода между двумя отрезками private int GetPeriod(DateSection dateSectionOne, DateSection dateSectionTwo) { DateTime startPeriodDate = DateTime.Compare(dateSectionOne.startDate, dateSectionTwo.startDate) == 1 ? dateSectionOne.startDate : dateSectionTwo.startDate; DateTime finalPeriodDate = DateTime.Compare(dateSectionOne.finalDate, dateSectionTwo.finalDate) == -1 ? dateSectionOne.finalDate : dateSectionTwo.finalDate; /* if ((start == dateSectionOne.startDate && end == dateSectionOne.finalDate) || (start == dateSectionTwo.startDate && end == dateSectionTwo.finalDate)) * { * return 0; * }*/ // else return(((finalPeriodDate - startPeriodDate).Days + 1) >= 0 ? ((finalPeriodDate - startPeriodDate).Days + 1) : 0); }
//Основной метод меню "Data" public override void Execute() { Console.WriteLine("Введите отрезок первой даты (Пример: 01.02.2003-04.05.2006):"); DateSection dateSectionOne = DateSectionInput(); Console.WriteLine("Введите отрезок второй даты (Пример: 01.02.2003-04.05.2006):"); DateSection dateSectionTwo = DateSectionInput(); int iPeriod = GetPeriod(dateSectionOne, dateSectionTwo); if (IsNotBigNumber(iPeriod)) { Console.WriteLine("Период: {0} \nРезультат выполнения функции Аккермана: {1}", iPeriod, AckermanFunc(iPeriod)); } }
//Метод, считытывания и обработки введенных в консоль данных. private DateSection DateSectionInput() { bool bIsSuccess = false; DateSection dataSection = new DateSection(); while (!bIsSuccess) { string sDateSection = Console.ReadLine(); bIsSuccess = IsCurrentDateSection(sDateSection); if (bIsSuccess) { string[] sDateArr = sDateSection.Split('-'); DateTime dateStart = DateTime.Parse(sDateArr[0]); DateTime dateFinal = DateTime.Parse(sDateArr[1]); bIsSuccess = IsNormalDataSection(dateStart, dateFinal); if (bIsSuccess) { dataSection.startDate = dateStart; dataSection.finalDate = dateFinal; } } } return(dataSection); }