aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSanJacobs2022-07-12 23:46:53 +0200
committerSanJacobs2022-07-12 23:46:53 +0200
commita04dd89365fcadf919bd486a75ba3e4f4629a45a (patch)
treec64ed8d5a1ba9c15382bfc52ff0ddab73eefa68a
parent62866cac4eb109490ad1d79a3295a3848da8c134 (diff)
downloadsatscalc-a04dd89365fcadf919bd486a75ba3e4f4629a45a.tar.gz
satscalc-a04dd89365fcadf919bd486a75ba3e4f4629a45a.tar.bz2
satscalc-a04dd89365fcadf919bd486a75ba3e4f4629a45a.zip
Made timeinput() vastly less tedious
-rwxr-xr-xsrc/main.cpp4
-rw-r--r--src/test.cpp2
-rwxr-xr-xsrc/time.cpp35
-rwxr-xr-xsrc/time.h2
4 files changed, 31 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..1d087f8 100755
--- a/src/time.cpp
+++ b/src/time.cpp
@@ -317,14 +317,33 @@ 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);
+ }
+
+ std::cout << "Split 01: " << split_input[0] << std::endl;
+ std::cout << "Split 02: " << split_input[1] << std::endl;
+
+ moment output{split_input[1], split_input[0],
+ input_moment.day, input_moment.month, input_moment.year};
return output;
}
diff --git a/src/time.h b/src/time.h
index 81111c1..fc5dcbc 100755
--- a/src/time.h
+++ b/src/time.h
@@ -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