4 * Created on: Dec 7, 2010
21 static const int CONST__DAYS_PER_MONTH[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
28 ltime = localtime(&wtime);
29 year = 1900 + ltime->tm_year;
30 month = ltime->tm_mon + 1; // ltime-month: values 0 - 11...
32 hour = ltime->tm_hour;
37 Date::Date(int year_param,
52 // TODO Auto-generated destructor stub
55 bool Date::is_leap_year() {
59 if ((year % 4 == 0) &&
60 ((year % 400 == 0) || (year % 100 != 0))) {
66 void Date::printout() {
67 log_debug("%d-%02d-%02d %02d:%02d:%02d\n", year, month, day, hour, min, sec);
73 ret_val = new Date(year,
82 void Date::copy(Date *date) {
91 bool Date::before(Date *date2) {
98 s1 = this->to_sortable_string();
99 s2 = date2->to_sortable_string();
100 if (s1.compare(s2) < 0) {
107 bool Date::equals(Date *date2) {
112 if ((this->sec == date2->sec) &&
113 (this->min == date2->min) &&
114 (this->hour == date2->hour) &&
115 (this->day == date2->day) &&
116 (this->month == date2->month) &&
117 (this->year == date2->year)) {
124 void Date::tomorrow() {
128 if (day > CONST__DAYS_PER_MONTH[month - 1]) {
130 (is_leap_year() == true) &&
146 void Date::next_hour() {
157 void Date::inc_minutes(int minutes) {
162 day_c = minutes / 1440;
163 minutes = minutes - day_c * 1440;
164 hour_c = minutes / 60;
165 minutes = minutes - hour_c * 60;
166 for (ii = 0; ii < day_c; ii++) {
169 for (ii = 0; ii < hour_c; ii++) {
187 void Date::inc_seconds(int seconds) {
190 min_c = seconds / 60;
191 seconds = seconds - min_c * 60;
200 string Date::to_sortable_string() {
204 sprintf(buffer, "%016d%02d%02d%02d%02d%02d", year, month, day, hour, min, sec);
209 string Date::to_string() {
213 sprintf(buffer, "%04d-%02d-%02d %02d:%02d:%02d", year, month, day, hour, min, sec);