Files
Meeting-Mixer/js/utils.js
T
ferdi2goandClaude Opus 4.8 fd9870871b 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>
2026-06-03 13:01:28 +00:00

29 lines
908 B
JavaScript

// Shared pure helpers used across modules.
// "YYYY-MM-DD" from numeric parts.
export function toISO(year, month, day) {
return year + '-' + String(month).padStart(2, '0') + '-' + String(day).padStart(2, '0');
}
// "YYYY-MM" month prefix (used to filter history by month).
export function monthPrefix(year, month) {
return year + '-' + String(month).padStart(2, '0');
}
// Weekday for an ISO date string: 1=Mo, 2=Di, 3=Mi, 4=Do, 5=Fr, 6=Sa, 7=So.
export function getWeekday(isoDate) {
const d = new Date(isoDate + 'T12:00:00Z').getUTCDay(); // 0=Sun
return d === 0 ? 7 : d;
}
// "DD.MM.YYYY" from an ISO date string.
export function formatDateDE(isoDate) {
const [y, m, d] = isoDate.split('-');
return d + '.' + m + '.' + y;
}
// { [id]: name } lookup map from an employees array.
export function buildNameMap(employees) {
return Object.fromEntries(employees.map(e => [e.id, e.name]));
}