#pragma once
class Date {
public:
Date(int year, int month, int day) : year(year), month(month), day(day) {}
int february_(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 tmp_day = this->day + days;
int tmp_month = this->month;
int tmp_year = this->year;
while (tmp_day > this->months[tmp_month - 1] + this->february_(tmp_month, tmp_year)) {
tmp_day -= this->months[tmp_month - 1] + this->february_(tmp_month, tmp_year);
tmp_month++;
if (tmp_month > 12) {
tmp_month = 1;
tmp_year++;
}
}
return {tmp_year, tmp_month, tmp_day};
}
int DaysLeft(const Date &date) const {
int i = 0;
while (!this->DaysLater(i).IsEqualTo(date)){
i++;
}
return i;
}
};