aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSanJacobs2022-07-27 22:15:15 +0200
committerSanJacobs2022-07-27 22:15:15 +0200
commit157f8160bdb1a1cf0c91c861ea4daceb6a954518 (patch)
tree63ba30d626d116dd5a8481438846c1e1e9859185 /src
parentdb37f3b69dc2d8d0a8994b1c1f0e3a55e07d4e62 (diff)
downloadsatscalc-157f8160bdb1a1cf0c91c861ea4daceb6a954518.tar.gz
satscalc-157f8160bdb1a1cf0c91c861ea4daceb6a954518.tar.bz2
satscalc-157f8160bdb1a1cf0c91c861ea4daceb6a954518.zip
Started work on lunch break feature
Diffstat (limited to 'src')
-rwxr-xr-xsrc/main.cpp12
-rwxr-xr-xsrc/time.cpp51
-rwxr-xr-xsrc/time.h13
3 files changed, 58 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<workday> workdays;
moment previous_wrap{0, 16, 20, 11, 1000}; // Set to a long time ago
for(int day=0; day<number_of_days; day++) {
+ // TODO: Asking for everything repeatedly like this is dumb,
+ // and needs to be replaced with a menu system.
+ // TODO: Inputing the dates should be done with a custom function and layout,
+ // not std::cin, because it openly allows for invalid input
std::cout << "\n - DAY " << day+1 << "-\nCalltime:\n";
moment calltime = timeinput();
std::cout << "\nWraptime:\n";
moment wraptime = timeinput(calltime);
std::cout << "\nPlanned wraptime:\n";
moment planned_wraptime = timeinput(calltime);
+ std::cout << "\nLunch start:\n";
+ moment lunch_start = timeinput(calltime);
+ std::cout << "\nLunch end:\n";
+ moment lunch_end = timeinput(calltime);
workdays.push_back({previous_wrap,
calltime,
wraptime,
planned_wraptime});
+ if(lunch_start != lunch_end) workdays[day].lunch(lunch_start, lunch_end);
+
workday* current_workday = &workdays[day];
std::cout << "\nCalltime: " << timeprint(current_workday->call) << "\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