diff options
-rwxr-xr-x | src/main.cpp | 13 | ||||
-rwxr-xr-x | src/time.cpp | 18 | ||||
-rwxr-xr-x | src/time.h | 22 |
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; +} // @@ -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) { |