feat: enhance timer metrics and workday calculations to include entries and running timer status

This commit is contained in:
Felix Schlusche
2025-10-31 18:54:17 +01:00
parent bad91636b5
commit d04ab18ba1
2 changed files with 38 additions and 7 deletions

View File

@@ -1162,6 +1162,15 @@ async function updateStatistics(entries) {
let futureFlextimeDays = 0; // Count future flextime days in current month
// Create a map to check if a day has an entry
const entriesMap = {};
entries.forEach(entry => {
entriesMap[entry.date] = entry;
});
const todayISO = getTodayISO();
const isCurrentMonth = currentYear === today.getFullYear() && currentMonth === today.getMonth();
for (let day = 1; day <= lastDay; day++) {
const dateObj = new Date(currentYear, currentMonth, day);
const year = dateObj.getFullYear();
@@ -1172,31 +1181,35 @@ async function updateStatistics(entries) {
const isVacation = vacationDays.has(dateISO);
const isFlextime = flextimeDays.has(dateISO);
const isWeekendHoliday = isWeekendOrHoliday(dateObj);
const hasEntry = entriesMap[dateISO];
const isToday = dateISO === todayISO;
// For today: only count as workday if there's an entry OR timer is running
const shouldCountToday = !isToday || hasEntry || (timerStartTime && isCurrentMonth);
if (!isWeekendHoliday && !isVacation && !isFlextime) {
// Normal workday (excluding vacation and flextime days)
totalWorkdaysInMonth++;
workdaysCount++;
if (dateObj <= today) {
if (dateObj <= today && shouldCountToday) {
workdaysPassed++;
}
} else if (!isWeekendHoliday && !isVacation && isFlextime) {
// Flextime on a workday - still counts as workday in calendar
totalWorkdaysInMonth++;
workdaysCount++;
if (dateObj <= today) {
if (dateObj <= today && shouldCountToday) {
workdaysPassed++;
} else {
// Future flextime in current month
const isCurrentMonth = currentYear === today.getFullYear() && currentMonth === today.getMonth();
if (isCurrentMonth) {
if (isCurrentMonth && dateObj > today) {
futureFlextimeDays++;
}
}
} else if (isFlextime && isWeekendHoliday) {
// Flextime on weekend/holiday counts as additional workday
totalWorkdaysInMonth++;
if (new Date(dateISO) <= today) {
if (new Date(dateISO) <= today && shouldCountToday) {
workdaysPassed++;
}
}
@@ -1212,7 +1225,6 @@ async function updateStatistics(entries) {
.reduce((sum, entry) => sum + entry.netHours, 0);
// Add currently running timer hours to actual hours (only for current month)
const isCurrentMonth = currentYear === today.getFullYear() && currentMonth === today.getMonth();
if (timerStartTime && isCurrentMonth) {
const now = Date.now();
let elapsedSeconds;