aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSanJacobs2022-04-19 00:21:04 +0200
committerSanJacobs2022-04-19 00:21:04 +0200
commit89ffc2637b6b8e33f55728e0132d62749c53ec1d (patch)
tree492d6602da604ce599a8941efa63557c112fe0c7 /src
parent181442ab4256f3c12ef0a62ed44e6e9fd0f58095 (diff)
downloadsatscalc-89ffc2637b6b8e33f55728e0132d62749c53ec1d.tar.gz
satscalc-89ffc2637b6b8e33f55728e0132d62749c53ec1d.tar.bz2
satscalc-89ffc2637b6b8e33f55728e0132d62749c53ec1d.zip
Tested and bugfixed delta-generation
I also added a beautiful operator<< overloading for deltas, I think it is very pretty.
Diffstat (limited to 'src')
-rwxr-xr-xsrc/main.cpp13
-rwxr-xr-xsrc/time.cpp18
-rwxr-xr-xsrc/time.h22
3 files changed, 37 insertions, 16 deletions
diff --git a/src/main.cpp b/src/main.cpp
index 91f04dd..e554fb1 100755
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -40,6 +40,16 @@ int main(int argc, char* argv[])
std::cout << "\nWorkday:\n";
std::cout << timeprint(workday) << std::endl;
+
+ std::cout << "\n\n --- TIME MATH TEST ---\n\n";
+
+ std::cout << "Difference between calltime and wraptime:\n";
+ std::cout << (calltime-wraptime) << std::endl;
+ std::cout << "Other way around, should show same result:\n";
+ std::cout << (calltime-wraptime) << std::endl;
+ std::cout << "As method on workday:\n";
+ std::cout << (workday.hourcount()) << std::endl;
+
std::cout << "\nSplitting workday into workday and second_half...\n";
moment splitpoint{0, 12, 27, 11, 2010};
timeblock second_half{timesplit(workday, splitpoint)};
@@ -55,8 +65,6 @@ int main(int argc, char* argv[])
std::cout << timeprint(timesplit(second_half, erronious_splitpoint));
- std::cout << "\n\n --- TIME MATH TEST ---\n\n";
-
moment testtime{30, 8, 25, 2, 2012};
std::cout << "Testtime: " << timeprint(testtime) << std::endl;
@@ -88,6 +96,7 @@ int main(int argc, char* argv[])
std::cout << "Testtime: " << timeprint(testtime) << std::endl;
+
std::cout << "\n\n --- TIME INPUT TEST ---\n\n";
moment inputmoment = timeinput();
diff --git a/src/time.cpp b/src/time.cpp
index 29af5be..78f2a53 100755
--- a/src/time.cpp
+++ b/src/time.cpp
@@ -60,20 +60,30 @@ delta moment::operator-(const moment& other) const {
while(decumulator.year - benchmark.year > 1 ||
decumulator.month - benchmark.month > 1 ||
decumulator.day - benchmark.day > 1) {
- wind(decumulator, 0, 0, 1);
+ wind(decumulator, 0, 0, -1);
accumulator.days++;
}
while(decumulator.hours - benchmark.hours > 1) {
- wind(decumulator, 0, 1, 0);
+ wind(decumulator, 0, -1, 0);
accumulator.hours++;
}
while(decumulator != benchmark) {
- wind(decumulator, 1, 0, 0);
- accumulator.minutes++;
+ wind(decumulator, -1, 0, 0);
+ accumulator.minutes = accumulator.minutes+1;
+ }
+ while(accumulator.minutes > 59) {
+ accumulator.minutes -= 60;
+ accumulator.hours++;
}
return accumulator;
}
+std::ostream& operator<<(std::ostream& stream, const delta& other) {
+ if(other.days) stream << other.days << " days, ";
+ if(other.hours) stream << other.hours << " hours, ";
+ if(other.minutes) stream << other.minutes << " minutes.";
+ return stream;
+}
//
diff --git a/src/time.h b/src/time.h
index b512e91..9e793ec 100755
--- a/src/time.h
+++ b/src/time.h
@@ -7,10 +7,11 @@
#include <vector>
struct delta{
- signed int minutes;
- signed int hours;
- signed int days;
+ unsigned int minutes;
+ unsigned int hours;
+ unsigned int days;
};
+std::ostream& operator<<(std::ostream& stream, const delta& other);
struct moment{
signed int minutes;
@@ -39,16 +40,17 @@ struct workday{
timeblock blocks[12];
//
// 1. sleepbreach
- // 2. Call
- // 3. Early morning
+ // 2. call
+ // 3. early morning
// 4. start of day
// 5. 1st hr overtime
// 6. post-1 hour overtime
- // 7. 14-hour mark
- // 8. 22:00
- // 9. midnight crossing
- // 10. 06:00
- // 11. wrap
+ // 7. end of warned ot
+ // 8. 14-hour mark
+ // 9. 22:00
+ // 10. midnight crossing
+ // 11. 06:00
+ // 12. wrap
//
workday(moment calltime, moment wraptime, moment planned_wraptime) {