Esempio n. 1
0
        public static TimeTI Diff(TimeTI first, TimeTI second)
        {
            if (first.Hours < second.Hours)
            {
                var temp = first;
                first  = second;
                second = temp;
            }
            var hours   = first.Hours - second.Hours;
            var minutes = first.Minutes - second.Minutes;
            var seconds = first.Seconds - second.Seconds;

            while (seconds < 0)
            {
                seconds += 60;
                minutes -= 1;
            }
            while (minutes < 0)
            {
                minutes += 60;
                hours   -= 1;
            }
            while (hours < 0)
            {
                hours += 23;
            }

            return(new TimeTI(hours, minutes, seconds));
        }
Esempio n. 2
0
        public static TimeTI Sum(TimeTI first, TimeTI second)
        {
            var sec  = first.Seconds + second.Seconds;
            var min  = 0;
            var hour = 0;

            while (sec >= 60)
            {
                min += 1;
                sec -= 60;
            }

            min += first.Minutes + second.Minutes;
            while (min >= 60)
            {
                hour += 1;
                min  -= 60;
            }
            hour += first.Hours + second.Hours;
            while (hour > 23)
            {
                hour -= 23;
            }

            return(new TimeTI(hour, min, sec));
        }
Esempio n. 3
0
        public void Sub(TimeTI time)
        {
            var res = Diff(this, time);

            Hours   = res.Hours;
            Minutes = res.Minutes;
            Seconds = res.Seconds;
        }
Esempio n. 4
0
        public void Add(TimeTI time)
        {
            var res = Sum(this, time);

            Hours   = res.Hours;
            Minutes = res.Minutes;
            Seconds = res.Seconds;
        }