refactor: centralize shared date/name helpers in utils.js (#12)

New js/utils.js exports toISO, monthPrefix, getWeekday, formatDateDE and
buildNameMap. algorithm.js, calendar.js, excel.js and history.js now import
these instead of re-implementing ISO construction, weekday math, DD.MM.YYYY
formatting and the id→name map inline. Adds tests/utils.test.mjs.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
ferdi2goandClaude Opus 4.8 committed 2026-06-03 13:01:28 +00:00
1 parent 0efb9cb853
commit fd9870871b
7 files changed
+71 -26

No files matched your search

+3 -3
View File
@@ -1,6 +1,7 @@
import { state, saveState } from './app.js';
import { loadFromJSON, saveToJSON, removeHistoryEntry } from './data.js';
import { downloadBlob } from './excel.js';
import { formatDateDE, buildNameMap } from './utils.js';
export function renderDataTab() {
const container = document.getElementById('tab-data');
@@ -102,7 +103,7 @@ function renderHistoryTable() {
return;
}
const nameById = Object.fromEntries(state.employees.map(e => [e.id, e.name]));
const nameById = buildNameMap(state.employees);
const sorted = [...state.history].sort((a, b) => {
const dateCmp = b.date.localeCompare(a.date);
if (dateCmp !== 0) return dateCmp;
@@ -124,11 +125,10 @@ function renderHistoryTable() {
const tbody = document.createElement('tbody');
for (const h of sorted) {
const [y, m, d] = h.date.split('-');
const tr = document.createElement('tr');
const dateTd = document.createElement('td');
dateTd.textContent = d + '.' + m + '.' + y;
dateTd.textContent = formatDateDE(h.date);
const nameTd = document.createElement('td');
nameTd.textContent = nameById[h.employeeId] ?? '(unbekannt)'; // textContent: safe