class Date {
public:
Date(int year, int month, int day) : year(year), month(month), day(day) {
};
bool IsLeap() const {
if (this->year % 400 == 0 || (this->year % 4 == 0 && this->year % 100 != 0))
return true;
else return false;
}
std::string ToString() const {
std::string str = "";
if (this->day < 10) {
str += '0' + std::to_string(this->day);
} else str += std::to_string(this->day);
str += '.';
if (this->month < 10) {
str += '0' + std::to_string(this->month);
} else str += std::to_string(this->month);
int num = this->year;
int len = 0;
while (num /= 10) len++;
std::string nul(3 - len, '0');
str += '.' + nul + std::to_string(this->year);
return str;
}
Date DaysLater(int days) const {
Date newDate = *this;
int DaysPerMonth[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
newDate.day += days;
while (newDate.day > DaysPerMonth[newDate.month]) {
if ((newDate.year % 4 == 0 && newDate.year % 100 != 0) || newDate.year % 400 == 0) {
DaysPerMonth[2] = 29;
}
newDate.day -= DaysPerMonth[newDate.month];
newDate.month++;
if (newDate.month > 12) {
newDate.month = 1;
newDate.year++;
}
}
return newDate;
}
int DaysLeft(const Date &date) const {
int a = (14 - this->month) / 12;
int y = this->year + 4800 - a;
int m = this->month + 12 * a - 3;
int jdn1 = this->day + ((153 * m + 2) / 5)
+ 365 * y + y / 4 - y / 100 + y / 400 - 32045;
a = (14 - date.month) / 12;
y = date.year + 4800 - a;
m = date.month + 12 * a - 3;
int jdn2 = date.day + ((153 * m + 2) / 5)
+ 365 * y + y / 4 - y / 100 + y / 400 - 32045;
return jdn2 - jdn1;
}
int year, month, day;
};