X-Git-Url: http://pilppa.org/gitweb/?a=blobdiff_plain;f=src%2FDate.cc;h=86b2cdc82a73bd28179ef36d8e9532f6dee9b0f7;hb=d01194ab9275bc97176071089edc2781bb4de51b;hp=d13d6d4798443fb9fd2c93875feb531289972e7e;hpb=56242039f27dc5d36117b8d513731c7a9009d4b1;p=lib1wire.git diff --git a/src/Date.cc b/src/Date.cc index d13d6d4..86b2cdc 100644 --- a/src/Date.cc +++ b/src/Date.cc @@ -121,6 +121,97 @@ bool Date::equals(Date *date2) { return ret_val; } +bool Date::before_or_equal_year(Date *date2) { + bool ret_val; + string s1; + string s2; + + ret_val = (this->year <= date2->year); + return ret_val; +} + +bool Date::before_or_equal_month(Date *date2) { + bool ret_val; + string s1; + string s2; + + ret_val = false; + if (this->year < date2->month) { + ret_val = true; + } + else { + if ((this->year == date2->year) && + (this->month <= date2->month)) { + ret_val = true; + } + } + return ret_val; +} + +bool Date::before_or_equal_day(Date *date2) { + bool ret_val; + string s1; + string s2; + + ret_val = false; + if (date2 != NULL) { + s1 = this->to_sortable_day_string(); + s2 = date2->to_sortable_day_string(); + if (s1.compare(s2) <= 0) { + ret_val = true; + } + } + return ret_val; +} + +bool Date::before_or_equal_hour(Date *date2) { + bool ret_val; + string s1; + string s2; + + ret_val = false; + if (date2 != NULL) { + s1 = this->to_sortable_hour_string(); + s2 = date2->to_sortable_hour_string(); + if (s1.compare(s2) <= 0) { + ret_val = true; + } + } + return ret_val; +} + +bool Date::before_or_equal_min(Date *date2) { + bool ret_val; + string s1; + string s2; + + ret_val = false; + if (date2 != NULL) { + s1 = this->to_sortable_min_string(); + s2 = date2->to_sortable_min_string(); + if (s1.compare(s2) <= 0) { + ret_val = true; + } + } + return ret_val; +} + +bool Date::before_or_equal(Date *date2) { + bool ret_val; + string s1; + string s2; + + ret_val = false; + if (date2 != NULL) { + s1 = this->to_sortable_string(); + s2 = date2->to_sortable_string(); + if (s1.compare(s2) <= 0) { + ret_val = true; + } + } + return ret_val; +} + void Date::tomorrow() { if ((month > 0) && (month <= 12)) { @@ -134,7 +225,7 @@ void Date::tomorrow() { else { day = 1; month++; - if (month == 12) { + if (month > 12) { year++; month = 1; } @@ -197,6 +288,35 @@ void Date::inc_seconds(int seconds) { } } +string Date::to_sortable_day_string() { + char buffer[30]; + + + string ret_val; + + sprintf(buffer, "%016d%02d%02d", year, month, day); + ret_val = buffer; + return ret_val; +} + +string Date::to_sortable_hour_string() { + char buffer[30]; + string ret_val; + + sprintf(buffer, "%016d%02d%02d%02d", year, month, day, hour); + ret_val = buffer; + return ret_val; +} + +string Date::to_sortable_min_string() { + char buffer[30]; + string ret_val; + + sprintf(buffer, "%016d%02d%02d%02d%02d", year, month, day, hour, min); + ret_val = buffer; + return ret_val; +} + string Date::to_sortable_string() { char buffer[30]; string ret_val;