Skip to content
Snippets Groups Projects
Commit 7bd593c1 authored by alrap417's avatar alrap417
Browse files

message

parent 4229a602
No related branches found
No related tags found
No related merge requests found
......@@ -14,6 +14,29 @@ if(check_invalid_format(hour, minute, second)) {
}
}
Time::Time(std::string const)
{
Time t{*this};
if(t.size() == 8 && t[2] == ':' && t[5] == ':') {
hour = stoi(t.substr(0, 2));
minute = stoi(t.substr(3, 2));
second = stoi(t.substr(6, 2));
}
if(check_invalid_format(hour, minute, second)) {
throw invalid_argument{"ogiltigt_varde"};
}
else
{
throw invalid_argument{"ogiltigt_format"};
}
}
/*
Time::Time(string h, string m, string s) : hour{h}, minute{m}, second{s} {
if(check_invalid_string(hour, minute, second)){
throw invalid_argument{"ogiltig_string"};
}
}*/
int Time::get_second() { //Gets current hour.
return second;
......@@ -27,7 +50,16 @@ int Time::get_hour() { //Gets current hour.
return hour;
}
/*bool Time::check_invalid_string(int const h, int const m, int const s){
//string fullstring = to_string(get_hour()) + ":" + to_string(get_minute()) + ":" + to_string(get_second());
//string fullstrin = istream
// if (fullstring[6] == "6") {
return true;
} else {
return false;
}
}
*/
bool Time::check_invalid_time(int const h, int const m, int const s){
if(h > 23 || h < 0 || m > 59 || m < 0 || s > 59 || s < 0)
{
......@@ -40,7 +72,7 @@ else
}
}
bool Time::check_invalid_format(int const h, int const m, int const s){
/*bool Time::check_invalid_format(int const h, int const m, int const s){
string fullstring = to_string(get_hour()) + ":" + to_string(get_minute()) + ":" + to_string(get_second());
if (fullstring.size() > 8) {
return true;
......@@ -130,6 +162,7 @@ bool Time::is_am() {
return false;
}
}
*/
string Time::to_string(const int data) {
std::ostringstream os{};
os << data;
......@@ -138,3 +171,6 @@ string Time::to_string(const int data) {
\ No newline at end of file
......@@ -21,14 +21,14 @@ public:
Time(int h , int m, int s);
Time() : hour{0}, minute{0}, second{0} {};
Time(bool text);
Time(string h, string m, string s);
Time(std::string const);
int get_hour();
int get_minute();
int get_second();
bool is_am();
string to_string(const int data); //Eget funktion
Time operator+(int const n) const;
Time operator++(int);
Time& operator++();
......@@ -49,6 +49,7 @@ private:
bool check_invalid_time(int const h, int const m, int const s);
bool check_default_time(int const h, int const m, int const s);
bool check_invalid_format(int const h, int const m, int const s);
bool check_invalid_string(int const h, int const m, int const s);
};
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment