fix: align analysis defaults to latest completed month

This commit is contained in:
hyunho
2026-03-30 10:27:21 +09:00
parent e67fd41cbf
commit 8121c9cf41
2 changed files with 111 additions and 33 deletions

View File

@@ -1546,10 +1546,10 @@
if (isNaN(d.getTime())) return "";
return `${d.getFullYear()}-${("0" + (d.getMonth() + 1)).slice(-2)}-${("0" + d.getDate()).slice(-2)}`;
};
const calculateTargetHours = (startStr, endStr) => {
const start = new Date(startStr);
const end = new Date(endStr);
if (isNaN(start.getTime()) || isNaN(end.getTime()) || end < start) return 0;
const calculateTargetHours = (startStr, endStr) => {
const start = new Date(startStr);
const end = new Date(endStr);
if (isNaN(start.getTime()) || isNaN(end.getTime()) || end < start) return 0;
const startUtc = Date.UTC(start.getFullYear(), start.getMonth(), start.getDate());
const endUtc = Date.UTC(end.getFullYear(), end.getMonth(), end.getDate());
const oneDay = 86400000;
@@ -1561,13 +1561,37 @@
const isWeekend = dayOfWeek === 0 || dayOfWeek === 6;
const isHoliday = isWeekend || HOLIDAYS.includes(dateText);
totalTarget += isHoliday ? HOLIDAY_TARGET_HOURS : WEEKDAY_TARGET_HOURS;
}
return Math.round(totalTarget);
};
const findHeaderIndex = (normalizedHeaders, candidates) => {
const targets = candidates.map(normalizeHeader);
for (let i = 0; i < normalizedHeaders.length; i++) {
if (targets.includes(normalizedHeaders[i])) return i;
}
return Math.round(totalTarget);
};
const formatLocalDate = (date) => {
if (!(date instanceof Date) || isNaN(date.getTime())) return '';
return `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, '0')}-${String(date.getDate()).padStart(2, '0')}`;
};
const getMonthRangeForDate = (date) => {
if (!(date instanceof Date) || isNaN(date.getTime())) return { startDate: '', endDate: '' };
const start = new Date(date.getFullYear(), date.getMonth(), 1);
const end = new Date(date.getFullYear(), date.getMonth() + 1, 0);
return {
startDate: formatLocalDate(start),
endDate: formatLocalDate(end)
};
};
const getDefaultMhDateRange = (dates = []) => {
const now = new Date();
const previousMonthRange = getMonthRangeForDate(new Date(now.getFullYear(), now.getMonth() - 1, 1));
const latestDateText = [...dates].filter(Boolean).sort().slice(-1)[0] || '';
const latestDate = latestDateText ? new Date(latestDateText) : null;
const previousMonthStart = new Date(now.getFullYear(), now.getMonth() - 1, 1);
if (latestDate instanceof Date && !isNaN(latestDate.getTime()) && latestDate < previousMonthStart) {
return getMonthRangeForDate(latestDate);
}
return previousMonthRange;
};
const findHeaderIndex = (normalizedHeaders, candidates) => {
const targets = candidates.map(normalizeHeader);
for (let i = 0; i < normalizedHeaders.length; i++) {
if (targets.includes(normalizedHeaders[i])) return i;
}
return -1;
};
@@ -2501,11 +2525,12 @@
function initTeamTabAfterUpload() {
if (teamData.length < 2) return;
const dates = teamData.slice(1).map(r => dStr(r[columnMap.date])).filter(Boolean).sort();
document.getElementById('start-date').value = dates[0];
document.getElementById('end-date').value = dates[dates.length - 1];
syncScopeButtons();
refreshScopedSelections(false);
render();
const defaultRange = getDefaultMhDateRange(dates);
document.getElementById('start-date').value = defaultRange.startDate;
document.getElementById('end-date').value = defaultRange.endDate;
syncScopeButtons();
refreshScopedSelections(false);
render();
lucide.createIcons();
}
@@ -2688,17 +2713,18 @@
if (mainSearch) mainSearch.value = '';
if (searchDropdown) searchDropdown.classList.add('hidden');
refreshScopedSelections(false);
if (personSelect) personSelect.value = '';
const dates = teamData.slice(1).map(r => dStr(r[columnMap.date])).filter(Boolean).sort();
if (dates.length > 0) {
startInput.value = dates[0];
endInput.value = dates[dates.length - 1];
}
render();
}
refreshScopedSelections(false);
if (personSelect) personSelect.value = '';
const dates = teamData.slice(1).map(r => dStr(r[columnMap.date])).filter(Boolean).sort();
if (dates.length > 0) {
const defaultRange = getDefaultMhDateRange(dates);
startInput.value = defaultRange.startDate;
endInput.value = defaultRange.endDate;
}
render();
}
document.getElementById('team-select').addEventListener('change', () => { updateFilters(); render(); });