diff options
-rwxr-xr-x | src/main.cpp | 11 | ||||
-rwxr-xr-x | src/time.cpp | 23 | ||||
-rwxr-xr-x | src/time.h | 2 |
3 files changed, 24 insertions, 12 deletions
diff --git a/src/main.cpp b/src/main.cpp index 21b25cc..f1dd13f 100755 --- a/src/main.cpp +++ b/src/main.cpp @@ -19,7 +19,6 @@ along with this program. If not, see https://www.gnu.org/licenses/ // TODO: Write function/method/constructor that slices a workday up into the differently priced segments // TODO: Make the system that determines the price of each of those slices of time // TODO: Add ruleset selector (That only allows you to pick the advert ruleset at first) -// TODO: Make cool logo #include <iostream> #include "time.h" @@ -52,17 +51,17 @@ int main(int argc, char* argv[]) std::cout << "\nSplitting workday into workday and second_half...\n"; moment splitpoint{0, 12, 27, 11, 2010}; - timeblock second_half{timesplit(workday, splitpoint)}; + timeblock first_half{timesplit(workday, splitpoint)}; std::cout << "\nSplitpoint: " << timeprint(splitpoint) << std::endl; + std::cout << "\nfirst_half:\n"; + std::cout << timeprint(first_half) << std::endl; std::cout << "\nWorkday:\n"; std::cout << timeprint(workday) << std::endl; - std::cout << "\nSecond_half:\n"; - std::cout << timeprint(second_half) << std::endl; std::cout << "\nSplitting second_half at erronious point...\n"; - moment erronious_splitpoint{0, 10, 27, 11, 2010}; - std::cout << timeprint(timesplit(second_half, erronious_splitpoint)) << "\n"; + moment erronious_splitpoint{0, 14, 27, 11, 2010}; + std::cout << timeprint(timesplit(first_half, erronious_splitpoint)) << "\n"; diff --git a/src/time.cpp b/src/time.cpp index 248d81b..3e65b45 100755 --- a/src/time.cpp +++ b/src/time.cpp @@ -33,6 +33,14 @@ bool moment::operator==(const moment& other) const { minutes==other.minutes); } +bool moment::operator<=(const moment& other) const { + return bool((*this < other) || *this == other); +} + +bool moment::operator>=(const moment& other) const { + return bool((*this > other) || *this == other); +} + bool moment::operator!=(const moment& other) const { return bool(year!=other.year || month!=other.month || @@ -121,6 +129,11 @@ workday::workday(const moment& previous_wrap, timeblock initial_block{call, wrap}; moment splitpoints[10]{ // --$-- Points where the price may change --$-- // + // NOTE: Maybe this should also contain the valuefactor associated with the split. + // Probably the valuefactor leading up to the splitpoint, not the one after. + // Maybe this should be a struct? + // Or maybe I should just implement this badly at first just to get it working, and replace it later? + previous_wrap+(delta){0, 10, 0}, // Sleepbreach, 10 hours after previous wrap (moment){0, 5, call.day, call.month, call.year}, // 2 hours before 7, aka 5 (moment){0, 6, call.day, call.month, call.year}, // 6 in the morning @@ -139,7 +152,7 @@ workday::workday(const moment& previous_wrap, const moment* each_moment = &splitpoints[i]; if(*each_moment > call && *each_moment < wrap) { blocks[j++] = timesplit(initial_block, *each_moment); - // FIXME: The way timesplit will work is to be reversed, so this will act as expected. + // TODO: Timesplit's input and return have been flipped, so check if this works } } @@ -177,18 +190,16 @@ std::string padint(const int input, const int minimum_signs) { } timeblock timesplit(timeblock& input_block, const moment splitpoint) { - // FIXME: Reverse the outputs. second_half replaces input_block, and return the first half. // 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. - if(splitpoint < input_block.start || splitpoint > input_block.end) { - // FIXME: This should use <= and >=, but they don't exist for moments... yet... ;) + if(splitpoint <= input_block.start || splitpoint >= input_block.end) { std::cerr << "ERROR: Splitpoint outside of timeblock!\n"; std::cerr << "Timeblock: " << timeprint(input_block) << std::endl; std::cerr << "Splitpoint: " << timeprint(splitpoint) << std::endl; } - timeblock output{splitpoint, input_block.end}; - input_block.end = splitpoint; + timeblock output{input_block.start, splitpoint}; + input_block.start = splitpoint; // Note: Now, reversed. return output; } @@ -34,6 +34,8 @@ 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; bool operator==(const moment& other) const; bool operator!=(const moment& other) const; delta operator-(const moment& other) const; |