diff options
author | SanJacobs | 2022-07-12 23:46:53 +0200 |
---|---|---|
committer | SanJacobs | 2022-07-12 23:50:12 +0200 |
commit | 4111b93bd116bf44f7e7b049630f011976b4b25c (patch) | |
tree | 64d15ad4901c9d4c9c41cd5e1e518025d66bd422 | |
parent | 62866cac4eb109490ad1d79a3295a3848da8c134 (diff) | |
download | satscalc-4111b93bd116bf44f7e7b049630f011976b4b25c.tar.gz satscalc-4111b93bd116bf44f7e7b049630f011976b4b25c.tar.bz2 satscalc-4111b93bd116bf44f7e7b049630f011976b4b25c.zip |
Made timeinput() vastly less tedious
-rwxr-xr-x | src/main.cpp | 4 | ||||
-rw-r--r-- | src/test.cpp | 2 | ||||
-rwxr-xr-x | src/time.cpp | 32 | ||||
-rwxr-xr-x | src/time.h | 2 |
4 files changed, 28 insertions, 12 deletions
diff --git a/src/main.cpp b/src/main.cpp index d3b0023..4d96c47 100755 --- a/src/main.cpp +++ b/src/main.cpp @@ -61,9 +61,9 @@ int main(int argc, char* argv[]) std::cout << "\n - DAY " << day+1 << "-\nCalltime:\n"; moment calltime = timeinput(); std::cout << "\nWraptime:\n"; - moment wraptime = timeinput(); + moment wraptime = timeinput(calltime); std::cout << "\nPlanned wraptime:\n"; - moment planned_wraptime = timeinput(); + moment planned_wraptime = timeinput(calltime); workdays.push_back({previous_wrap, calltime, diff --git a/src/test.cpp b/src/test.cpp index 3d6d78b..8d36f3a 100644 --- a/src/test.cpp +++ b/src/test.cpp @@ -78,6 +78,6 @@ void test(){ moment inputmoment = timeinput(); std::cout << "Time reveived: " << timeprint(inputmoment) << std::endl; - moment inputmoment2 = timeinput(2012, 11, 26); + moment inputmoment2 = timeinput(inputmoment); std::cout << "Time reveived: " << timeprint(inputmoment2) << std::endl; } diff --git a/src/time.cpp b/src/time.cpp index 98a5482..9ecdc69 100755 --- a/src/time.cpp +++ b/src/time.cpp @@ -317,14 +317,30 @@ int days_in(int month, int year) { } // TODO: Add checks for correct formatting, and ask for new input if wrong -moment timeinput(const moment) { - char input_string[5]; - std::cout << "Input time\nHHMM (24-hour format, no space)\n"; - std::cin >> input_string; - moment output{std::stoi(std::string(std::string(1, input_string[2])+input_string[3])), - std::stoi(std::string(std::string(1, input_string[0])+input_string[1])), - or_day, or_month, or_year}; - // This is retarded and needs to be completely replaced +moment timeinput(moment input_moment) { + char input_string[6]; + std::cout << "HH MM (24-hour format, use space)\n"; + std::cin.getline(input_string, 6); + + // This uglyness is just how you use strtok() to split a string, apparently + const char* p; + int split_input[2]; + int i{0}; + p = strtok(input_string, " "); + while (p != NULL) { + split_input[i] = int(atoi(p)); + i++; + p = strtok(NULL, " "); + } + + if((moment){split_input[1], split_input[0], + input_moment.day, input_moment.month, input_moment.year} < input_moment) + { + wind(input_moment, 0, 0, 1); + } + + moment output{split_input[1], split_input[0], + input_moment.day, input_moment.month, input_moment.year}; return output; } @@ -97,7 +97,7 @@ std::string timeprint(const moment input_moment); std::string timeprint(const timeblock input_timeblock); long sortable_time(const timeblock input_timeblock); -moment timeinput(const int or_year, const int or_month, const int or_day); +moment timeinput(moment input_moment); moment timeinput(); // TODO: It would be nice to have a version that can take in a const reference to a moment, prompt for clock-time, and return the first moment at that clock-time forward in time from the input moment |