From 157f8160bdb1a1cf0c91c861ea4daceb6a954518 Mon Sep 17 00:00:00 2001 From: SanJacobs Date: Wed, 27 Jul 2022 22:15:15 +0200 Subject: Started work on lunch break feature --- src/main.cpp | 12 +++++++++++- src/time.cpp | 51 +++++++++++++++++++++++++++++++++++++++++---------- src/time.h | 13 ++++++------- test.sh | 6 ++++++ 4 files changed, 64 insertions(+), 18 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 2deba1d..a9d1543 100755 --- a/src/main.cpp +++ b/src/main.cpp @@ -50,25 +50,35 @@ int main(int argc, char* argv[]) std::cout << "How many days do you want to submit?" << std::endl; int number_of_days; // std::cin >> number_of_days; - number_of_days = 3; // Just here for debugging + number_of_days = 1; // Just here for debugging std::vector workdays; moment previous_wrap{0, 16, 20, 11, 1000}; // Set to a long time ago for(int day=0; daycall) << "\n"; diff --git a/src/time.cpp b/src/time.cpp index ee8f139..3e18828 100755 --- a/src/time.cpp +++ b/src/time.cpp @@ -176,20 +176,12 @@ workday::workday(const moment& previous_wrap, // TODO: Implement a good system for this fuckin' paragraph: // A. 50 % tillegg for arbeid inntil 2 timer før, eller inntil 3 timer etter ordinær arbeidstid når arbeidstiden ikke er forskjøvet og overtiden er varslet. Dersom det varsles overtid både før og etter ordinær arbeidstid betales de to første timene med 50 % tillegg og de øvrige med 100 % tillegg. + // TODO: Add the ability to cut out a lunch break for(int ii=0; ii < total_timeblocks; ii++){ timeblock& each_block = blocks[ii]; std::cout << "pricing: " << timeprint(each_block) << std::endl; - if(each_block.hourcount() == 8) { - each_block.valuefactor = 7.5/8.0; - if(each_block.start.getweekday() == saturday) each_block.valuefactor *= 1.5; - if(each_block.start.getweekday() == sunday) each_block.valuefactor *= 2; - // TODO: This is a bad solution, but it makes other stuff easier for now. - // Note: Yes, a simple float is capable of storing 7.5/8*1.5 perfectly. - // The real solution is to be able to add lunchbreaks. - // Note: It is starting to look like this band-aid solution is untennable even for basic functionality. - continue; - } + if(each_block.end <= splitpoints[0]) each_block.upvalue(3); // +200% for sleep-breach if(each_block.start.hours >= 22) each_block.upvalue(2); // Work between 22:00 if((each_block.end.hours == 6 && each_block.end.minutes == 0) ||// And 06:00 @@ -204,6 +196,45 @@ workday::workday(const moment& previous_wrap, } +void workday::lunch(const moment& lunch_start, const moment& lunch_end) { + if(lunch_start > lunch_end){ + std::cout << "ERROR: Lunch ends before it began." << std::endl; + } + for(int ii=0; ii < total_timeblocks; ii++){ + timeblock& each_block = blocks[ii]; + timeblock& next_block = blocks[ii+1]; + + if(each_block.start < lunch_start && each_block.end > lunch_end){ + // If lunch simply occurs within a timeblock + // Split out the section, discarding the middle + timeblock second_half = timesplit(each_block, lunch_start); + second_half.start = lunch_end; + // Move all points after lunch out by 1 + for(int x=total_timeblocks; x>ii; x--) { + blocks[x+1] = blocks[x]; + } + total_timeblocks++; + // Re-insert second half of split section into ii+1 + blocks[ii+1] = second_half; + + } else if(each_block.start < lunch_start && lunch_start < each_block.end && + next_block.start < lunch_end && lunch_end < next_block.end) { + // If lunch occurs between two timeblocks + each_block.end = lunch_start; + next_block.start = lunch_end; + + } else if(each_block.start == lunch_start) { + // If lunch starts at the beginning of a timeblock + each_block.start = lunch_end; + + } else if(each_block.end == lunch_end) { + // If lunch ends at the end of a timeblock + each_block.start = lunch_end; + } + return; + } +} + // // --- METHODS --- diff --git a/src/time.h b/src/time.h index 5711aaf..ff228d3 100755 --- a/src/time.h +++ b/src/time.h @@ -56,11 +56,11 @@ struct workday{ moment call; moment wrap; moment planned_wrap; - timeblock blocks[12]; + timeblock blocks[15]; int total_timeblocks; - // total_timeblocks exsists because blocks[13] can't be shrunk, - // so total_timeblocks is the point at which blocks[13] just contains - // garbage data. + // total_timeblocks exsists because blocks can't be shrunk, + // so total_timeblocks is the point at which blocks + // just contains garbage data. // // 1. call // 2. sleepbreach @@ -79,13 +79,12 @@ struct workday{ const moment& calltime, const moment& wraptime, const moment& planned_wraptime); + void lunch(const moment& lunch_start, const moment& lunch_end); }; std::string padint(const int input, const int minimum_signs); timeblock timesplit(timeblock& input_block, const moment splitpoint); - // XXX: I have now found that it would be really nice if the first half is returned, - // and the second half replaces the instance at input_block; // 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. @@ -101,5 +100,5 @@ long sortable_time(const timeblock input_timeblock); moment timeinput(moment input_moment); moment timeinput(); -// TODO: It would be nice to have a version that can take in a const reference to a moment, prompt for clock-time, and return the first moment at that clock-time forward in time from the input moment +// TODO: Completely re-write timeinput to be beautiful and enforce valid dates diff --git a/test.sh b/test.sh index 00d49b6..e25a523 100755 --- a/test.sh +++ b/test.sh @@ -2,11 +2,17 @@ 2022 11 20 08 00 02 00 19 45 +12 00 +12 30 2022 11 22 08 30 19 30 19 00 +12 00 +12 30 2022 11 24 14 00 23 30 23 00 +18 00 +18 30 EOF-MARKER -- cgit v1.2.1