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:
1 parent
0efb9cb853
commit
fd9870871b
7 files changed
+71
-26
No files matched your search
+1
-10
@@ -1,13 +1,4 @@
|
||||
function toISO(year, month, day) {
|
||||
return year + '-' + String(month).padStart(2, '0') + '-' + String(day).padStart(2, '0');
|
||||
}
|
||||
|
||||
// Returns 1=Mo, 2=Di, 3=Mi, 4=Do, 5=Fr, 6=Sa, 7=So
|
||||
function getWeekday(isoDate) {
|
||||
const d = new Date(isoDate + 'T12:00:00Z');
|
||||
const day = d.getUTCDay(); // 0=Sun
|
||||
return day === 0 ? 7 : day;
|
||||
}
|
||||
import { toISO, getWeekday } from './utils.js';
|
||||
|
||||
function isOnVacation(employee, isoDate) {
|
||||
return employee.constraints.vacations.some(v => v.from <= isoDate && isoDate <= v.to);
|
||||
|
||||
Reference in new issue
Block a user