]> pilppa.org Git - lib1wire.git/blobdiff - src/Date.cc
Optimization for year and monthly data calculation.
[lib1wire.git] / src / Date.cc
index e45b544fc6073d40ba431f2c6eeb0d1693cc4edf..a93c0cd21b7e382573f7fb6dae07ea82d05e6cfa 100644 (file)
@@ -212,15 +212,33 @@ bool Date::before_or_equal(Date *date2) {
        return ret_val;
 }
 
+void Date::next_second() {
+       if (sec < 59) {
+               sec++;
+       }
+       else {
+               next_min();
+       }
+}
+
+void Date::next_min() {
+       if (min < 59) {
+               sec     = 0;
+               min++;
+       }
+       else {
+               next_hour();
+       }
+}
+
 void Date::next_hour() {
-       sec     = 0;
-       min     = 0;
        hour++;
-       if (hour < 0) {
-               hour    = 0;
+       if (hour < 23) {
+               sec     = 0;
+               min     = 0;
+               hour++;
        }
-       if (hour >= 24) {
-               hour    = 0;
+       else {
                next_day();
        }
 }
@@ -228,34 +246,31 @@ void Date::next_hour() {
 void Date::next_day() {
        if ((month > 0) &&
            (month <= 12)) {
-               day++;
-               if (day > CONST__DAYS_PER_MONTH[month - 1]) {
-                       if ((month == 2) &&
-                           (is_leap_year() == true) &&
-                           (day == 29)) {
-                               // ok
-                       }
-                       else {
-                               day     = 1;
-                               month++;
-                               if (month > 12) {
-                                       year++;
-                                       month   = 1;
-                               }
-                       }
+               if ((day < CONST__DAYS_PER_MONTH[month - 1]) ||
+                   ((month == 2) &&
+                    (is_leap_year() == true) &&
+                    (day == 28))) {
+                       sec     = 0;
+                       min     = 0;
+                       hour    = 0;
+                       day++;
+               }
+               else {
+                       next_month();
                }
        }
 }
 
 void Date::next_month() {
-       sec     = 0;
-       min     = 0;
-       hour    = 0;
-       day     = 1;
-       month++;
-       if (month > 12) {
-               month   = 1;
-               year++;
+       if (month < 12) {
+               sec     = 0;
+               min     = 0;
+               hour    = 0;
+               day     = 1;
+               month++;
+       }
+       else {
+               next_year();
        }
 }