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 bool Date::before_or_equal_year(Date *date2) {
129 ret_val = (this->year <= date2->year);
133 bool Date::before_or_equal_month(Date *date2) {
139 if (this->year < date2->month) {
143 if ((this->year == date2->year) &&
144 (this->month <= date2->month)) {
151 bool Date::before_or_equal_day(Date *date2) {
158 s1 = this->to_sortable_day_string();
159 s2 = date2->to_sortable_day_string();
160 if (s1.compare(s2) <= 0) {
167 bool Date::before_or_equal_hour(Date *date2) {
174 s1 = this->to_sortable_hour_string();
175 s2 = date2->to_sortable_hour_string();
176 if (s1.compare(s2) <= 0) {
183 bool Date::before_or_equal_min(Date *date2) {
190 s1 = this->to_sortable_min_string();
191 s2 = date2->to_sortable_min_string();
192 if (s1.compare(s2) <= 0) {
199 bool Date::before_or_equal(Date *date2) {
206 s1 = this->to_sortable_string();
207 s2 = date2->to_sortable_string();
208 if (s1.compare(s2) <= 0) {
215 void Date::tomorrow() {
219 if (day > CONST__DAYS_PER_MONTH[month - 1]) {
221 (is_leap_year() == true) &&
237 void Date::next_hour() {
248 void Date::inc_minutes(int minutes) {
253 day_c = minutes / 1440;
254 minutes = minutes - day_c * 1440;
255 hour_c = minutes / 60;
256 minutes = minutes - hour_c * 60;
257 for (ii = 0; ii < day_c; ii++) {
260 for (ii = 0; ii < hour_c; ii++) {
278 void Date::inc_seconds(int seconds) {
281 min_c = seconds / 60;
282 seconds = seconds - min_c * 60;
291 string Date::to_sortable_day_string() {
297 sprintf(buffer, "%016d%02d%02d", year, month, day);
302 string Date::to_sortable_hour_string() {
306 sprintf(buffer, "%016d%02d%02d%02d", year, month, day, hour);
311 string Date::to_sortable_min_string() {
315 sprintf(buffer, "%016d%02d%02d%02d%02d", year, month, day, hour, min);
320 string Date::to_sortable_string() {
324 sprintf(buffer, "%016d%02d%02d%02d%02d%02d", year, month, day, hour, min, sec);
329 string Date::to_string() {
333 sprintf(buffer, "%04d-%02d-%02d %02d:%02d:%02d", year, month, day, hour, min, sec);