Hello everyone) The essence of the problem is that you need to write a class to set the time from a year to seconds (I did it). + Write methods for adding hours, minutes, seconds to an existing date, taking into account all transitions so that I can add 100500 hours and get a real date. Thanks in advance for the answer!

class DateControl { private string year; private string mounth; private string day; private string hour; private string minutes; private string seconds; private bool isLeap = false; private int[] mn = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; public DateControl(string year) { } public string SetYear { set { int check = Convert.ToInt32(value); if (check < 0) { check = check * (-1); } if (DateTime.IsLeapYear(check)) { isLeap = true; } this.year = Convert.ToString(check); } get { return this.year; } } /*public void setYear(string year) { int check = Convert.ToInt32(mounth); if (check < 0) { check = check * (-1); } if (DateTime.IsLeapYear(check)) { isLeap = true; } this.year = Convert.ToString(check); }*/ public void setMounth(string mounth) { int check= Convert.ToInt32(mounth); if(check<1 || check > 12) { showError(); } else this.mounth = mounth; } public void setDay(string day) { int check = Convert.ToInt32(day); if (check < 1 || check > mn[Convert.ToInt32(mounth)]) { showError(); } else this.day = day; } public void setHour(string hour) { int check = Convert.ToInt32(hour); if (check < 0 || check > 23) { showError(); } else this.hour = hour; } public void setMinute(string minutes) { int check = Convert.ToInt32(minutes); if (check < 0 || check > 59) { showError(); } else this.minutes = minutes; } public void setSecond(string seconds) { int check = Convert.ToInt32(minutes); if (check < 0 || check > 59) { showError(); } else this.seconds = seconds; } //////////////////////////////////////////////// //добавить часы public void addHours(string hourCount) { int reserve = Convert.ToInt32(hour) + Convert.ToInt32(hourCount); if (reserve <= 23) { this.hour = Convert.ToString(reserve); return; }else if (reserve > 23) { //дальше непонятно } } //добавить минуты public void addMinutes(string hourCount) { } //секунды public void addSeconds(string hourCount) { } public void showError() { Console.WriteLine("Error!"); } public string toString() { string reurnString = "" + year + "." + mounth + "." + day + " " + hour + ":" + minutes + ":" + seconds; return reurnString; } 
  • Do you know about the existence of a DateTime type in C #? msdn.microsoft.com/en-us/library/… - Igor
  • Such a method already exists: DateTime.Add(TimeSpan) . Do not reinvent the wheel. - VladD
  • @VladD the fact of the matter is that you need to write your entire class with your methods. - Serhiy
  • If you need your own, then using DateTime.IsLeapYear not fair;). - Alexander Petrov
  • So it is) But I need to know how to complete all the transitions when adding minutes there or hours. This is the essence of the issue - Serhiy

0