summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/Result.jsx28
1 files changed, 13 insertions, 15 deletions
diff --git a/src/Result.jsx b/src/Result.jsx
index c8a367e..0dc9b9a 100644
--- a/src/Result.jsx
+++ b/src/Result.jsx
@@ -60,13 +60,13 @@ function fetchApi(year) {
}
function segmentTime(duration, segments) {
- const segmentSum = segments.reduce((partialSum, a) => partialSum + a, 0);
- const segmentsFilled = [...segments, 24 - segmentSum];
+ // const segmentSum = segments.reduce((partialSum, a) => partialSum + a, 0);
+ // const segmentsFilled = [...segments, 24 - segmentSum];
const segmentedHours = [];
- for (const[index, segmentDuration] of segmentsFilled.entries()) {
- if (index < segmentsFilled.length - 1) {
- const hours = Math.min(duration, segmentDuration);
+ for (const[index, segmentDuration] of segments.entries()) {
+ if (index < segments.length - 1) {
+ const hours = Math.min(duration, segmentDuration.segment);
segmentedHours.push(hours);
duration -= hours;
} else {
@@ -92,25 +92,23 @@ function calculatePerDay(entry, baseSalary, holidayData) {
const overtimeDuration = entry.finish.diff(entry.start, 'hour', true);
let multiplier = 0;
- // TODO: find better way
- const multiplierMap = {
+ const segmentMap = {
workDays: [
- 1.5, // jam pertama
- 2
+ {segment: 1, multiplier: 1.5}, // jam pertama
+ {segment: 23, multiplier: 2}
],
holidays: [
- 2, // 8 jam pertama
- 3, // jam ke 9
- 4
+ {segment: 8, multiplier: 2}, // 8 jam pertama
+ {segment: 1, multiplier: 3}, // jam ke 9
+ {segment: 15, multiplier: 4}
]
}
- const segmentPattern = isHoliday(entry.date) ? [8, 1, 15] : [1, 23];
+ const segmentPattern = isHoliday(entry.date) ? segmentMap.holidays : segmentMap.workDays;
const segmentedDuration = segmentTime(overtimeDuration, segmentPattern);
- const usedMap = isHoliday(entry.date) ? multiplierMap.holidays : multiplierMap.workDays;
for (let i = 0; i < segmentedDuration.length; i++) {
if (segmentedDuration[i])
- multiplier += segmentedDuration[i] * usedMap[i];
+ multiplier += segmentedDuration[i] * segmentPattern[i].multiplier;
}
return multiplier * hourlyPay;