time(&wtime);
ltime = localtime(&wtime);
year = 1900 + ltime->tm_year;
- month = ltime->tm_mon;
+ month = ltime->tm_mon + 1; // ltime-month: values 0 - 11...
day = ltime->tm_mday;
hour = ltime->tm_hour;
min = ltime->tm_min;
ret_val = false;
if ((year % 4 == 0) &&
- (year % 400 == 0) || (year % 100 != 0)) {
+ ((year % 400 == 0) || (year % 100 != 0))) {
ret_val = true;
}
return ret_val;
Date *Date::clone() {
Date *ret_val;
- ret_val = new Date(this->year,
- this->month,
- this->day,
- this->hour,
- this->min,
- this->sec);
+ ret_val = new Date(year,
+ month,
+ day,
+ hour,
+ min,
+ sec);
return ret_val;
}
void Date::copy(Date *date) {
- this->year = date->year;
- this->month = date->month;
- this->day = date->day;
- this->hour = date->hour;
- this->min = date->min;
- this->sec = date->sec;
+ year = date->year;
+ month = date->month;
+ day = date->day;
+ hour = date->hour;
+ min = date->min;
+ sec = date->sec;
}
bool Date::before(Date date2) {
bool ret_val;
- string s1 = this->to_string();
- string s2 = date2.to_string();
+ string s1 = this->to_sortable_string();
+ string s2 = date2.to_sortable_string();
ret_val = false;
if (s1.compare(s2) < 0) {
ret_val = true;
}
}
-string Date::to_string() {
+void Date::next_hour() {
+ if ((hour >= 0) &&
+ (hour <= 24)) {
+ hour++;
+ if (hour > 24) {
+ hour = 0;
+ tomorrow();
+ }
+ }
+}
+
+void Date::inc_minutes(int minutes) {
+ int day_c;
+ int hour_c;
+ int ii;
+
+ day_c = minutes / 1440;
+ minutes = minutes - day_c * 1440;
+ hour_c = minutes / 60;
+ minutes = minutes - hour_c * 60;
+ for (ii = 0; ii < day_c; ii++) {
+ tomorrow();
+ }
+ for (ii = 0; ii < hour_c; ii++) {
+ hour++;
+ if (hour > 24) {
+ hour = 0;
+ tomorrow();
+ }
+ }
+ min = min + minutes;
+ if (min >= 60) {
+ min = min % 60;
+ hour++;
+ if (hour > 24) {
+ hour = 0;
+ tomorrow();
+ }
+ }
+}
+
+void Date::inc_seconds(int seconds) {
+ int min_c;
+
+ min_c = seconds / 60;
+ seconds = seconds - min_c * 60;
+ inc_minutes(min_c);
+ sec = sec + seconds;
+ if (sec >= 60) {
+ sec = sec % 60;
+ inc_minutes(1);
+ }
+}
+
+string Date::to_sortable_string() {
char buffer[30];
string ret_val;
- int n, a=5, b=3;
sprintf(buffer, "%016d%02d%02d%02d%02d%02d", year, month, day, hour, min, sec);
ret_val = buffer;
return ret_val;
}
+
+string Date::to_string() {
+ char buffer[30];
+ string ret_val;
+
+ sprintf(buffer, "%04d-%02d-%02d %02d:%02d:%02d", year, month, day, hour, min, sec);
+ ret_val = buffer;
+ return ret_val;
+}