#pragma once
#include <string>
class Date {
private:
int day, month, year;
int MonthsGenerator(int value) const {
int size;
if (value == 1 || value == 3 || value == 5 || value == 7 || value ==8 ||
value == 10 || value == 12) size = 31;
if (value == 4 || value == 6 || value == 9 || value == 11) size =30;
if (value == 2) {
if (this->IsLeap()) size = 29;
else
size = 28;
}
return size;
}
std::string add0(std::string word, unsigned int type) const {
for (; word.size() < type; word = '0' + word) {}
return word;
}
std::string Removeint(int value) const {
std::string newString ="";
while (value > 0) {
newString = const_cast<char>(value % 10 + 48) + newString;
value /= 10;
}
return newString;
}
bool operator==(Date other) {
if ((year == other.year)&&(month == other.month)&&(day == other.day)) {
return true;
} else {
return false;
}
}
bool operator!=(Date other) {
if ((year != other.year) || (month != other.month) || (day != other.day)) {
return true;
} else {
return false;
}
}
public:
Date(int year, int month, int day): year(year), month(month), day(day) {}
bool IsLeap() const {
bool flag;
if (year % 4 == 0 && year % 100 !=0) flag = true;
if (year % 400 == 0) flag = true;
if (year % 4 != 0) flag = false;
return flag;
}
std :: string ToString() const {
std::string barnYear, barnMonth, barnDay;
int valYear = year, valMonth = month, valDay = day;
std::string resString = add0(Removeint(valDay), 2) + '.'
+ add0(Removeint(valMonth), 2) + '.' + add0(Removeint(valYear), 4);
return resString;
}
Date DaysLater(int value) const {
int barnDay = day + value, barnMonth = month, barnYear = year;
while ((barnDay-1) / MonthsGenerator(barnMonth) > 0) {
barnDay -= MonthsGenerator(barnMonth);
barnMonth++;
if (barnMonth > 12) {
barnMonth -= 12;
barnYear++;
}
}
return Date(barnYear, barnMonth, barnDay);
}
int DaysLeft(const Date& otherDate) const {
int i = 0;
while(this->DaysLater(i) != otherDate) {
i++;
if (this->DaysLater(i) == otherDate) break;
}
return i;
}
};