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

+4 -5
View File
@@ -1,3 +1,5 @@
import { formatDateDE, buildNameMap } from './utils.js';
// Reads employee names from first column of xlsx (skips header row 0)
export function readEmployeeNames(arrayBuffer) {
const wb = XLSX.read(arrayBuffer, { type: 'array' });
@@ -19,7 +21,7 @@ export function sanitizeCell(value) {
// Pure helper: returns { names: [...], dates: [...] } columns for a schedule.
// Multiple employees per date are joined alphabetically with " & ".
export function buildScheduleColumns(assignments, employees) {
const nameById = Object.fromEntries(employees.map(e => [e.id, e.name]));
const nameById = buildNameMap(employees);
const byDate = new Map();
for (const a of assignments) {
if (!byDate.has(a.date)) byDate.set(a.date, []);
@@ -29,10 +31,7 @@ export function buildScheduleColumns(assignments, employees) {
const names = sortedDates.map(d =>
sanitizeCell(byDate.get(d).slice().sort((x, y) => x.localeCompare(y, 'de')).join(' & '))
);
const dates = sortedDates.map(d => {
const [y, m, day] = d.split('-');
return day + '.' + m + '.' + y;
});
const dates = sortedDates.map(formatDateDE);
return { names, dates };
}