Example #1
0
        public static TimeClass operator -(TimeClass time1, TimeClass time2)
        {
            TimeClass time3 = new TimeClass();

            time3.h = time1.h - time2.h;
            time3.m = time1.m - time2.m;
            time3.s = time1.s - time2.s;

            if (time3.s < 0)
            {
                time3.s *= -1;
                time3.s -= 60;
                time3.s *= -1;
                time3.m--;
            }
            if (time3.m < 0)
            {
                time3.m *= -1;
                time3.m -= 60;
                time3.m *= -1;
                time3.h--;
            }
            if (time3.h < 0)
            {
                time3.h += 24;
            }
            return(time3);
        }
Example #2
0
        private void Button_sub_Click(object sender, EventArgs e)
        {
            TimeClass sub = new TimeClass();

            sub            = t1 - t2;
            label_str.Text = sub.convert_to_string();
        }
Example #3
0
        private void Button_plus_Click(object sender, EventArgs e)
        {
            TimeClass sum = new TimeClass();

            sum            = t1 + t2;
            label_str.Text = sum.convert_to_string();
        }
Example #4
0
        } //возвращение секунд

        public static TimeClass operator +(TimeClass time1, TimeClass time2)
        {
            TimeClass time3 = new TimeClass();

            time3.s = time1.s + time2.s;
            time3.m = time1.m + time2.m;
            time3.h = time1.h + time2.h;

            if (time3.s > 59)
            {
                time3.s -= 60;
                time3.m++;
            }
            if (time3.m > 59)
            {
                time3.m -= 60;
                time3.h++;
            }
            if (time3.h > 23)
            {
                time3.h -= 24;
            }
            return(time3);
        }