#pragma once
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <string>
#include <ctime>


class Date {
 public:
int y, m, d;

explicit Date(int year, int month, int day) {
y = year;
m = month;
d = day;
}

bool IsLeap() const {
if ((this->y % 4 == 0 && this->y % 100 != 0) || this->y % 400 == 0)
return 1;
return 0;
}

std::string ToString() const {
std::string str_d = std::to_string(this->d + 100).erase(0, 1);
std::string str_m = std::to_string(this->m + 100).erase(0, 1);
std::string str_y = std::to_string(this->y + 10000).erase(0, 1);
std::string str_date = str_d + "." + str_m + "." + str_y;
return str_date;
}

Date DaysLater(int days) const {
int new_d = this->d;
int new_m = (this->m + 9) % 12;
int new_y = this->y - new_m / 10;;
int64 days_count = 365 * new_y + new_y / 4 - new_y / 100 + new_y / 400 + 
(new_m * 306 + 5) / 10 + (new_d - 1);
days_count += days;
new_y = (10000 * days_count + 14780) / 3652425;
int ddd = days_count - (365 * new_y + new_y / 4 - new_y / 100 + new_y / 400);
if (ddd < 0) {
new_y = new_y - 1;
ddd = days_count - (365 * new_y + new_y / 4 - new_y / 100 + new_y / 400);
}
int mi = (100 * ddd + 52) / 3060;
int mm = (mi + 2) % 12 + 1;
new_y = new_y + (mi + 2) / 12;
int dd = ddd - (mi * 306 + 5) / 10 + 1;
Date new_date(new_y, mm, dd);
return new_date;
}

int DaysLeft(const Date& date) const {
time_t tmp = { 0 };
struct std::tm a = *localtime_r(&tmp);;
struct std::tm b = *localtime_r(&tmp);;
a = { 0, 0, 0, this->d, this->m, this->y };
b = { 0, 0, 0, date.d, date.m, date.y };
std::time_t x = std::mktime(&a);
std::time_t y = std::mktime(&b);
if (x != (std::time_t)(-1) && y != (std::time_t)(-1)) {
double difference = std::difftime(y, x) / (60 * 60 * 24);
return difference;
}
return 0;
}
};