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 /src/time.cpp | |
parent | 62866cac4eb109490ad1d79a3295a3848da8c134 (diff) | |
download | satscalc-4111b93bd116bf44f7e7b049630f011976b4b25c.tar.gz satscalc-4111b93bd116bf44f7e7b049630f011976b4b25c.tar.bz2 satscalc-4111b93bd116bf44f7e7b049630f011976b4b25c.zip |
Made timeinput() vastly less tedious
Diffstat (limited to 'src/time.cpp')
-rwxr-xr-x | src/time.cpp | 32 |
1 files changed, 24 insertions, 8 deletions
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; } |