diff options
author | SanJacobs | 2022-04-16 01:41:13 +0200 |
---|---|---|
committer | SanJacobs | 2022-04-16 01:41:13 +0200 |
commit | 539b4c108e8eced7fef3324a9daa2ef0a538477b (patch) | |
tree | 585ba88bc622de66ed365e2c893d0e6e9fbd8b9d /src/time.cpp | |
parent | b99fe6cb748be0cf018540180bf19edd1bb1a698 (diff) | |
download | satscalc-539b4c108e8eced7fef3324a9daa2ef0a538477b.tar.gz satscalc-539b4c108e8eced7fef3324a9daa2ef0a538477b.tar.bz2 satscalc-539b4c108e8eced7fef3324a9daa2ef0a538477b.zip |
Wrote function to input time and date
Diffstat (limited to 'src/time.cpp')
-rwxr-xr-x | src/time.cpp | 45 |
1 files changed, 44 insertions, 1 deletions
diff --git a/src/time.cpp b/src/time.cpp index 8f12d3d..b4bfa1e 100755 --- a/src/time.cpp +++ b/src/time.cpp @@ -3,7 +3,10 @@ // Look. listen here. There's no way I'm going to start taking DST into account. // I have to draw the line somewhere, and frankly, once you start doing "Change an hour on the 4th moon of the 2nd week of March in France, but only if the tulips haven't sprung... etc... etc.." I'm out. -// Operator overloads: +// +// --- OPERATOR OVERLOADS --- +// + bool moment::operator<(const moment& other) const{ // Converts moments to strings and casts them as ints to compare using namespace std; @@ -49,6 +52,11 @@ bool moment::operator=(const moment& other) const { minutes==other.minutes); } + +// +// --- FUNCTIONS --- +// + std::string padint(const int input, const int minimum_signs) { std::ostringstream output; output << std::internal << std::setfill('0') << std::setw(minimum_signs) << input; @@ -170,3 +178,38 @@ int days_in(int month, int year) { std::cout << "Something just went very wrong. You found month #" << std::to_string(month) << '\n'; return 5; } + +// TODO: Add checks for correct formatting, and ask for new input if wrong +moment timeinput(int or_year, int or_month, int or_day) { + 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 + return output; +} +moment timeinput() { + char input_string[17]; + std::cout << "Input date and time\nYEAR MM DD hh mm (24-hour format, use spaces)\n"; + std::cin.getline(input_string, 17); + + // This uglyness is just how you use strtok() to split a string, apparently + const char* p; + int split_input[5]; + int i{0}; + p = strtok(input_string, " "); + while (p != NULL) { + split_input[i] = int(atoi(p)); + i++; + p = strtok(NULL, " "); + } + + moment output{split_input[4], + split_input[3], + split_input[2], + split_input[1], + split_input[0]}; + return output; +} |