fix: improve holiday name retrieval by comparing year, month, and day directly to avoid timezone issues

refactor: change exported variables to local scope in state management for better encapsulation
This commit is contained in:
Felix Schlusche
2025-10-23 19:36:55 +02:00
parent 426859ea0d
commit af23aa369c
3 changed files with 63 additions and 64 deletions

View File

@@ -1,38 +1,18 @@
// ============================================
// STATE & VARIABLES
// STATE & VARIABLES (additional to state.js)
// ============================================
let currentEditingId = null;
let datePicker = null;
let startTimePicker = null;
let endTimePicker = null;
let filterFromPicker = null;
let filterToPicker = null;
let manualStartTimePicker = null;
// Timer state
let timerInterval = null;
let timerStartTime = null;
let timerPausedDuration = 0; // Total paused time in seconds
let isPaused = false;
let pauseTimeout = null;
// Additional timer state (beyond state.js)
let pauseStartElapsed = 0; // Elapsed time when pause started (to freeze display)
let pauseEndTime = 0; // Timestamp when pause will end (for countdown)
let timerStartTimeString = ''; // Start time as string (HH:MM) for display
let currentEntryId = null; // ID of today's entry being timed
// Current month display state
let displayYear = new Date().getFullYear();
let displayMonth = new Date().getMonth(); // 0-11
// Current view state
let currentView = 'monthly'; // 'monthly' or 'filter'
let currentFilterFrom = null;
let currentFilterTo = null;
// Bulk edit state
let bulkEditMode = false;
let selectedEntries = new Set();
// Settings state
let currentBundesland = 'BW'; // Default: Baden-Württemberg
let totalVacationDays = 30; // Default vacation days per year
@@ -2109,7 +2089,10 @@ async function bulkExportPDF() {
// Count workdays based on selected entries only
selectedDates.forEach(dateISO => {
const dateObj = new Date(dateISO);
// Parse date correctly to avoid timezone issues
const [year, month, day] = dateISO.split('-').map(Number);
const dateObj = new Date(year, month - 1, day);
const isVacation = vacationDaysSet.has(dateISO);
const isFlextime = flextimeDaysSet.has(dateISO);
const isWeekendHoliday = isWeekendOrHoliday(dateObj);
@@ -2975,8 +2958,19 @@ async function handleExportPDF() {
// Calculate statistics
const today = new Date();
today.setHours(23, 59, 59, 999); // Set to end of day to include today
// Count workdays (excluding weekends and holidays, only up to today)
// Find the last entry date to calculate workdays up to (parse correctly to avoid timezone issues)
let lastEntryDate = today;
if (entries.length > 0) {
const sortedEntries = entries.sort((a, b) => b.date.localeCompare(a.date));
const lastDateStr = sortedEntries[0].date; // "2025-10-22"
const [year, month, day] = lastDateStr.split('-').map(Number);
lastEntryDate = new Date(year, month - 1, day, 23, 59, 59, 999);
}
// Count workdays (excluding weekends and holidays, up to last entry or today, whichever is later)
const countUntil = lastEntryDate > today ? lastEntryDate : today;
let workdaysPassed = 0;
let totalWorkdaysInMonth = 0;
@@ -3008,13 +3002,13 @@ async function handleExportPDF() {
if (!isWeekendHoliday && !isVacation) {
// Normal workday (excluding vacation days)
totalWorkdaysInMonth++;
if (dateObj <= today) {
if (dateObj <= countUntil) {
workdaysPassed++;
}
} else if (isFlextime && isWeekendHoliday) {
// Flextime on weekend/holiday counts as additional workday
totalWorkdaysInMonth++;
if (new Date(dateISO) <= today) {
if (new Date(dateISO) <= countUntil) {
workdaysPassed++;
}
}
@@ -3037,7 +3031,7 @@ async function handleExportPDF() {
entries.forEach(entry => {
const entryDate = new Date(entry.date);
if (entryDate <= today) {
if (entryDate <= countUntil) {
if (!entry.entryType || entry.entryType === 'work') {
totalNetHours += entry.netHours;
workEntriesCount++;