aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xsrc/main.cpp15
-rwxr-xr-xsrc/time.cpp45
-rwxr-xr-xsrc/time.h10
3 files changed, 66 insertions, 4 deletions
diff --git a/src/main.cpp b/src/main.cpp
index 3c12dae..a952bbe 100755
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -58,6 +58,7 @@ int main(int argc, char* argv[])
moment erronious_splitpoint{0, 10, 27, 11, 2010};
std::cout << timeprint(timesplit(second_half, erronious_splitpoint));
+
std::cout << "\n\n --- TIME MATH TEST ---\n\n";
moment testtime{30, 8, 25, 2, 2012};
@@ -89,8 +90,22 @@ int main(int argc, char* argv[])
std::cout << "\nRewinding 10 days...\n";
wind(testtime, 0, 0, -10);
std::cout << "Testtime: " << timeprint(testtime) << std::endl;
+
+
+ std::cout << "\n\n --- TIME INPUT TEST ---\n\n";
+
+ moment inputmoment = timeinput();
+ std::cout << "Time reveived: " << timeprint(inputmoment) << std::endl;
+ moment inputmoment2 = timeinput(2012, 11, 26);
+ std::cout << "Time reveived: " << timeprint(inputmoment2) << std::endl;
}
}
+ std::cout << "satscalc (C++ Edition)\n";
+ std::cout << "Copyright 2022 Sander J. Skjegstad.\n";
+ std::cout << "This is free software with ABSOLUTELY NO WARRENTY.\n";
+ std::cout << "It does NOT give financial advice.\n\n";
+
+ std::cout << "-----\nStep 1: Adding the days\n\n";
return 0;
}
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;
+}
diff --git a/src/time.h b/src/time.h
index f597c2d..4dfa1ff 100755
--- a/src/time.h
+++ b/src/time.h
@@ -3,6 +3,7 @@
#include <sstream>
#include <ios>
#include <iomanip>
+#include <string.h>
struct moment{
signed int minutes;
@@ -30,9 +31,12 @@ timeblock timesplit(timeblock &input_block, const moment splitpoint);
void wind(moment &input_moment, const int minutes, const int hours, const int days);
-int days_in(int month, int year);
+int days_in(const int month, const int year);
-std::string timeprint(moment input_moment);
+std::string timeprint(const moment input_moment);
-std::string timeprint(timeblock input_timeblock);
+std::string timeprint(const timeblock input_timeblock);
+
+moment timeinput(const int or_year, const int or_month, const int or_day);
+moment timeinput();