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) {
94 string s1 = this->to_sortable_string();
95 string s2 = date2.to_sortable_string();
97 if (s1.compare(s2) < 0) {
103 bool Date::equals(Date date2) {
107 if ((this->sec == date2.sec) &&
108 (this->min == date2.min) &&
109 (this->hour == date2.hour) &&
110 (this->day == date2.day) &&
111 (this->month == date2.month) &&
112 (this->year == date2.year)) {
118 void Date::tomorrow() {
122 if (day > CONST__DAYS_PER_MONTH[month - 1]) {
124 (is_leap_year() == true) &&
140 void Date::next_hour() {
151 void Date::inc_minutes(int minutes) {
156 day_c = minutes / 1440;
157 minutes = minutes - day_c * 1440;
158 hour_c = minutes / 60;
159 minutes = minutes - hour_c * 60;
160 for (ii = 0; ii < day_c; ii++) {
163 for (ii = 0; ii < hour_c; ii++) {
181 void Date::inc_seconds(int seconds) {
184 min_c = seconds / 60;
185 seconds = seconds - min_c * 60;
194 string Date::to_sortable_string() {
198 sprintf(buffer, "%016d%02d%02d%02d%02d%02d", year, month, day, hour, min, sec);
203 string Date::to_string() {
207 sprintf(buffer, "%04d-%02d-%02d %02d:%02d:%02d", year, month, day, hour, min, sec);