Massdownload
This commit is contained in:
@@ -74,6 +74,49 @@ function formatDateTime(dateStr) {
|
||||
return date.toLocaleString('de-DE');
|
||||
}
|
||||
|
||||
// Helper: Berechnet Kalenderwoche aus einem Datum (ISO 8601)
|
||||
function getCalendarWeek(dateStr) {
|
||||
const date = new Date(dateStr);
|
||||
const d = new Date(Date.UTC(date.getFullYear(), date.getMonth(), date.getDate()));
|
||||
const dayNum = d.getUTCDay() || 7;
|
||||
d.setUTCDate(d.getUTCDate() + 4 - dayNum);
|
||||
const yearStart = new Date(Date.UTC(d.getUTCFullYear(), 0, 1));
|
||||
const weekNo = Math.ceil((((d - yearStart) / 86400000) + 1) / 7);
|
||||
return weekNo;
|
||||
}
|
||||
|
||||
// Helper: Berechnet week_start (Montag) und week_end (Sonntag) aus Jahr und Kalenderwoche (ISO 8601)
|
||||
function getWeekDatesFromCalendarWeek(year, weekNumber) {
|
||||
// ISO 8601: Woche beginnt am Montag, erste Woche enthält den 4. Januar
|
||||
const jan4 = new Date(Date.UTC(year, 0, 4));
|
||||
const jan4Day = jan4.getUTCDay() || 7; // 1 = Montag, 7 = Sonntag
|
||||
const daysToMonday = jan4Day === 1 ? 0 : 1 - jan4Day;
|
||||
|
||||
// Montag der ersten Woche
|
||||
const firstMonday = new Date(Date.UTC(year, 0, 4 + daysToMonday));
|
||||
|
||||
// Montag der gewünschten Woche (Woche 1 = erste Woche)
|
||||
const weekMonday = new Date(firstMonday);
|
||||
weekMonday.setUTCDate(firstMonday.getUTCDate() + (weekNumber - 1) * 7);
|
||||
|
||||
// Sonntag der Woche (6 Tage nach Montag)
|
||||
const weekSunday = new Date(weekMonday);
|
||||
weekSunday.setUTCDate(weekMonday.getUTCDate() + 6);
|
||||
|
||||
// Format: YYYY-MM-DD
|
||||
const formatDate = (date) => {
|
||||
const y = date.getUTCFullYear();
|
||||
const m = String(date.getUTCMonth() + 1).padStart(2, '0');
|
||||
const d = String(date.getUTCDate()).padStart(2, '0');
|
||||
return `${y}-${m}-${d}`;
|
||||
};
|
||||
|
||||
return {
|
||||
week_start: formatDate(weekMonday),
|
||||
week_end: formatDate(weekSunday)
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
hasRole,
|
||||
getDefaultRole,
|
||||
@@ -82,5 +125,7 @@ module.exports = {
|
||||
calculateBreakMinutes,
|
||||
updateTotalHours,
|
||||
formatDate,
|
||||
formatDateTime
|
||||
formatDateTime,
|
||||
getCalendarWeek,
|
||||
getWeekDatesFromCalendarWeek
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user