26 lines
722 B
C++

#include "Date.h"
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);
}
Date Date::getDateFromString(std::string date) {
for (int i = 0; i < date.size(); ++i) {
if ((date[i] < '0' or date[i] > '9') and date[i] != '.') throw UnparseableDateException(date);
}
std::string tmp;
unsigned int dd[3] = {0,0,0};
std::stringstream stram(date);
for (int i = 0; i < 3; ++i) {
getline (stram,tmp, '.');
dd[i] = std::stoi(tmp);
}
return {dd[0], dd[1], dd[2]};
}