45 lines
1002 B
C++

#include "Date.h"
std::ostream& operator<<(std::ostream &out, const Date &date) {
return out << date.toString();
}
Date::Date(unsigned int day, unsigned int month, unsigned int year) : day(day), month(month), year(year) {}
std::string Date::toString() const {
return std::to_string(day) + ", " + std::to_string(month) + ", " + std::to_string(year);
}
bool Date::operator==(const Date &other) const {
return this->year == other.year && this->month == other.month && this->day == other.day;
}
//prefix ++a
Date& Date::operator++() {
day++;
if(months[month-1] < day){
month++;
day = 1;
}
if(month == 13){
year++;
month = 1;
}
return *this;
}
//postfix a++
Date Date::operator++(int dummy) {
Date tmp(day,month,year);
day++;
if(months[month-1] < day){
month++;
day = 1;
}
if(month == 13){
year++;
month = 1;
}
return tmp;
}