Implemented hour addition and subtraction.
[libacl.git] / src / hour.cpp
index 26b7a30..347b656 100644 (file)
@@ -135,6 +135,23 @@ hour hour::operator+=(hour t)
    return *this;
 }
 
+hour hour::increase()
+{
+   seconds ++;
+   if (seconds >= 60)
+   {
+      minutes++;
+      seconds -= 60;
+   }
+   if (minutes >= 60)
+   {
+      hours++;
+      minutes -= 60;
+   }
+
+   return *this;
+}
+
 hour operator-(hour &t1, hour &t2)
 {
    hour t = t1;
@@ -158,6 +175,45 @@ hour operator-(hour &t1, hour &t2)
    return t;
 }
 
+hour hour::operator-=(hour t)
+{
+   seconds -= t.seconds;
+   if (seconds < 0)
+   {
+      minutes--;
+      seconds += 60;
+   }
+
+   minutes -= t.minutes;
+   if (minutes < 0)
+   {
+      hours--;
+      minutes += 60;
+   }
+
+   hours -= t.hours;
+
+   return *this;
+}
+
+hour hour::decrease()
+{
+   seconds --;
+   if (seconds < 0)
+   {
+      minutes--;
+      seconds += 60;
+   }
+
+   if (minutes < 0)
+   {
+      hours--;
+      minutes += 60;
+   }
+
+   return *this;
+}
+
 std::ostream& operator<<(std::ostream &s, const hour &t)
 {
    s.width(2);