consolidate all repos to one for archive
This commit is contained in:
61
semester_2/programiranje_2/naloga0901/Date.cpp
Normal file
61
semester_2/programiranje_2/naloga0901/Date.cpp
Normal file
@@ -0,0 +1,61 @@
|
||||
|
||||
#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;
|
||||
}
|
||||
|
||||
|
||||
Date& Date::operator++() {
|
||||
day++;
|
||||
if (months[month - 1] < day) {
|
||||
month++;
|
||||
day = 1;
|
||||
}
|
||||
if (month == 13) {
|
||||
year++;
|
||||
month = 1;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
Date Date::operator+(int days) {
|
||||
Date tmp(day,month,year);
|
||||
tmp.day += days;
|
||||
// while (months[tmp.month - 1] < tmp.day){
|
||||
// tmp.day = tmp.day - months[tmp.month-1];
|
||||
// tmp.month++;
|
||||
// if (tmp.month == 13) {
|
||||
// tmp.year++;
|
||||
// tmp.month = 1;
|
||||
// }
|
||||
// }
|
||||
for(int i = 0; i<days ; i++){
|
||||
tmp++;
|
||||
}
|
||||
return tmp;
|
||||
}
|
||||
Reference in New Issue
Block a user