diff options
-rwxr-xr-x | src/time.cpp | 52 | ||||
-rwxr-xr-x | src/time.h | 33 |
2 files changed, 46 insertions, 39 deletions
diff --git a/src/time.cpp b/src/time.cpp index b4bfa1e..384eb83 100755 --- a/src/time.cpp +++ b/src/time.cpp @@ -7,44 +7,23 @@ // --- OPERATOR OVERLOADS --- // +long sortable_time(const moment input_moment) { + return stol(std::to_string(input_moment.year)+ + padint(input_moment.month,2)+ + padint(input_moment.day,2)+ + padint(input_moment.hours,2)+ + padint(input_moment.minutes,2)); +} + bool moment::operator<(const moment& other) const{ - // Converts moments to strings and casts them as ints to compare - using namespace std; - string left_moment_string{ - to_string(year)+ - padint(month,2)+ - padint(day,2)+ - padint(hours,2)+ - padint(minutes,2)}; - string right_moment_string{ - to_string(other.year)+ - padint(other.month,2)+ - padint(other.day,2)+ - padint(other.hours,2)+ - padint(other.minutes,2)}; - long left_int = stol(left_moment_string); - long right_int = stol(right_moment_string); - return bool(left_int < right_int); + return bool(sortable_time(*this) < sortable_time(other)); } + bool moment::operator>(const moment& other) const{ - using namespace std; - string left_moment_string{ - to_string(year)+ - padint(month,2)+ - padint(day,2)+ - padint(hours,2)+ - padint(minutes,2)}; - string right_moment_string{ - to_string(other.year)+ - padint(other.month,2)+ - padint(other.day,2)+ - padint(other.hours,2)+ - padint(other.minutes,2)}; - long left_int = stol(left_moment_string); - long right_int = stol(right_moment_string); - return bool(left_int > right_int); + return bool(sortable_time(*this) > sortable_time(other)); } -bool moment::operator=(const moment& other) const { + +bool moment::operator==(const moment& other) const { return bool(year==other.year && month==other.month && day==other.day && @@ -63,7 +42,7 @@ std::string padint(const int input, const int minimum_signs) { return output.str(); } -timeblock timesplit(timeblock &input_block, const moment splitpoint) { +timeblock timesplit(timeblock& input_block, const moment splitpoint) { // Splits a timeblock at splitpoint. // It changes the input_block to end at splitpoint, and returns a new timeblock // that lasts from splitpoint to where the input_block used to end. @@ -77,7 +56,7 @@ timeblock timesplit(timeblock &input_block, const moment splitpoint) { return output; } -void wind(moment &input_moment, const int minutes, const int hours, const int days) { +void wind(moment& input_moment, const int minutes, const int hours, const int days) { // Adding minutes input_moment.minutes += minutes; @@ -142,6 +121,7 @@ std::string timeprint(timeblock input_timeblock) { return output; } + int days_in(int month, int year) { // Kind of a stupid and slow way to do this // But it's nice to have it as a function @@ -4,6 +4,7 @@ #include <ios> #include <iomanip> #include <string.h> +#include <vector> struct moment{ signed int minutes; @@ -14,7 +15,7 @@ struct moment{ bool operator<(const moment& other) const; bool operator>(const moment& other) const; - bool operator=(const moment& other) const; + bool operator==(const moment& other) const; }; struct timeblock{ @@ -22,9 +23,35 @@ struct timeblock{ moment end; }; +struct workday{ + moment call; + moment wrap; + moment planned_wrap; + timeblock blocks[12]; + // + // 1. sleepbreach + // 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 + // + workday(moment calltime, moment wraptime, moment planned_wraptime) { + + } + workday(moment previous_wrap, moment calltime, moment wraptime, moment planned_wraptime) { + + } +}; + std::string padint(const int input, const int minimum_signs); -timeblock timesplit(timeblock &input_block, const moment splitpoint); +timeblock timesplit(timeblock& input_block, const moment splitpoint); // Splits a timeblock at splitpoint. // It changes the input_block to end at splitpoint, and returns a new timeblock // that lasts from splitpoint to where the input_block used to end. @@ -34,8 +61,8 @@ void wind(moment &input_moment, const int minutes, const int hours, const int da int days_in(const int month, const int year); 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(); |