#include <string>
class Date {
public:
Date(int year, int month, int day) : year(year), month(month), day(day) {}
int IsFeb(int month, int year) const {
if (month == 2 && Date(year, month, 1).IsLeap())
return 1;
else
return 0;
}
bool IsEqualTo(Date date) const {
if (this->year == date.year && this->month == date.month &&
this->day == date.day)
return true;
else
return false;
}
int year, month, day;
int months[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
bool IsLeap() const {
if (this->year % 4 == 0) {
if (this->year % 100 == 0) {
if (this->year % 400 == 0)
return true;
else
return false;
} else {
return true;
}
} else {
return false;
}
}
std::string ToString() const {
return (this->day < 10 ? "0" : "") + std::to_string(this->day) +
"." + (this->month < 10 ? "0" : "") +
std::to_string(this->month) + "." +
(this->year < 1000 ? "0" : "") + (this->year < 100 ? "0" : "") +
(this->year < 10 ? "0" : "") + std::to_string(this->year);
}
Date DaysLater(int days) const {
int tempd = this->day + days;
int tempm = this->month;
int tempy = this->year;
while (tempd > this->months[tempm - 1] + this->IsFeb(tempm, tempy)) {
tempd -= this->months[tempm - 1] + this->IsFeb(tempm, tempy);
tempm++;
if (tempm > 12) {
tempm = 1;
tempy++;
}
}
return {tempy, tempm, tempd};
}
int DaysLeft(const Date &date) const {
int i = 0;
while (!this->DaysLater(i).IsEqualTo(date))
i++;
return i;
}
};