public string WhatLesson(MyTime mt) { MyTime timeX = new MyTime(8, 0, 0); if (Difference(mt, timeX) <= 0) { return("пари ще не почалися"); } int[] breaksLenghtsMinutes = { 20, 20, 20, 20, 10 }; for (int lessNumber = 0; lessNumber < breaksLenghtsMinutes.Length; lessNumber++) { timeX = AddSeconds(timeX, 80 * 60); // пара if (Difference(mt, timeX) < 0) { return(string.Format("{0}-а пара", lessNumber + 1)); } if (lessNumber == breaksLenghtsMinutes.Length - 1) { break; } timeX = AddSeconds(timeX, breaksLenghtsMinutes[lessNumber] * 60); // перерва if (Difference(mt, timeX) < 0) { return(string.Format("перерва між {0}-ю та {1}-ю парами", lessNumber + 1, lessNumber + 2)); } } return("пари вже скінчилися"); }
static void Main(string[] args) { MyTime t = new MyTime(0, 0, 0); // час (головний) t.Hour = 12; // години t.Minute = 40; // хвилини t.Second = 1; // секунди MyTime mt1 = new MyTime(0, 0, 0); // перший момент часу mt1.Hour = 13; mt1.Minute = 45; mt1.Second = 43; MyTime mt2 = new MyTime(0, 0, 0); // другий момент часу mt2.Hour = 9; mt2.Minute = 14; mt2.Second = 21; Console.WriteLine("{0} - час", t); Console.WriteLine("{0}(с) - перевод часу в секунди", t.TimeSinceMidnight(t)); Console.WriteLine("{0} - додає до часу одну секунду", t.AddOneSecond(t)); Console.WriteLine("{0} - додає до часу одну хвилину", t.AddOneMinute(t)); Console.WriteLine("{0} - додає до часу одну годину", t.AddOneHour(t)); Console.WriteLine("Скільки секунд ви б хотіли додати?", t.AddOneHour(t)); int s = Int32.Parse(Console.ReadLine()); Console.WriteLine("{0} - додає до часу {1}-кількість секунд", t.AddSeconds(t, s), s); Console.WriteLine("Перший момент часу {0} - другий момент часу {1}", mt1, mt2); Console.WriteLine("{0} - різниця між цими моментами", t.TimeSinceMidnight(t.Difference(mt1, mt2))); Console.WriteLine("Введіть спершу години, потім з нового рядка хвилини і так само секунди!"); int[] array = new int[3]; for (int i = 0; i < array.Length; i++) { array[i] = Int32.Parse(Console.ReadLine()); } MyTime mt = new MyTime(0, 0, 0); mt.Hour = array[0]; mt.Minute = array[1]; mt.Second = array[2]; Console.WriteLine("{0} - зараз {1}", mt, t.WhatLesson(mt)); Console.ReadKey(); }
public int TimeSinceMidnight(MyTime t) { return(t.hour * 3600 + t.minute * 60 + t.second); }
public int Difference(MyTime mt1, MyTime mt2) { return(TimeSinceMidnight(mt1) - TimeSinceMidnight(mt2)); }
public MyTime AddSeconds(MyTime t, int s) { return(TimeSinceMidnight(TimeSinceMidnight(t) + s)); }
public MyTime AddOneHour(MyTime t) { return(TimeSinceMidnight(TimeSinceMidnight(t) + 3600)); }
public MyTime AddOneMinute(MyTime t) { return(TimeSinceMidnight(TimeSinceMidnight(t) + 60)); }
public MyTime AddOneSecond(MyTime t) { return(TimeSinceMidnight(TimeSinceMidnight(t) + 1)); }