consolidate all repos to one for archive
This commit is contained in:
25
semester_2/programiranje_2/naloga1102/Date.cpp
Normal file
25
semester_2/programiranje_2/naloga1102/Date.cpp
Normal file
@@ -0,0 +1,25 @@
|
||||
#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]};
|
||||
}
|
||||
Reference in New Issue
Block a user