This commit is contained in:
Felix Schlusche
2025-10-23 01:12:59 +02:00
parent c8c2a800bb
commit 2804b3eaa4
12 changed files with 875 additions and 324 deletions

View File

@@ -0,0 +1,68 @@
/**
* Date utility functions
*/
/**
* Format date from YYYY-MM-DD to DD.MM.YYYY
* @param {string} dateStr - Date in YYYY-MM-DD format
* @returns {string} - Date in DD.MM.YYYY format
*/
export function formatDateDisplay(dateStr) {
const [year, month, day] = dateStr.split('-');
return `${day}.${month}.${year}`;
}
/**
* Format date from DD.MM.YYYY to YYYY-MM-DD
* @param {string} dateStr - Date in DD.MM.YYYY format
* @returns {string} - Date in YYYY-MM-DD format
*/
export function formatDateISO(dateStr) {
const [day, month, year] = dateStr.split('.');
return `${year}-${month}-${day}`;
}
/**
* Get today's date in YYYY-MM-DD format
* @returns {string} - Today's date
*/
export function getTodayISO() {
const today = new Date();
const year = today.getFullYear();
const month = String(today.getMonth() + 1).padStart(2, '0');
const day = String(today.getDate()).padStart(2, '0');
return `${year}-${month}-${day}`;
}
/**
* Get day of week name in German
* @param {Date} date - Date object
* @returns {string} - German day name (Mo, Di, Mi, etc.)
*/
export function getDayOfWeek(date) {
const days = ['So', 'Mo', 'Di', 'Mi', 'Do', 'Fr', 'Sa'];
return days[date.getDay()];
}
/**
* Get month name in German
* @param {number} monthIndex - Month index (0-11)
* @returns {string} - German month name
*/
export function getMonthName(monthIndex) {
const months = [
'Januar', 'Februar', 'März', 'April', 'Mai', 'Juni',
'Juli', 'August', 'September', 'Oktober', 'November', 'Dezember'
];
return months[monthIndex];
}
/**
* Check if date is weekend or holiday
* @param {Date} date - Date object
* @returns {boolean} - True if weekend or holiday
*/
export function isWeekendOrHoliday(date) {
const dayOfWeek = date.getDay();
return dayOfWeek === 0 || dayOfWeek === 6; // Sunday or Saturday
}

View File

@@ -0,0 +1,54 @@
/**
* Time utility functions
*/
/**
* Round time down to nearest 15 minutes
* @param {Date} date - Date object
* @returns {Date} - Rounded date
*/
export function roundDownTo15Min(date) {
const minutes = date.getMinutes();
const roundedMinutes = Math.floor(minutes / 15) * 15;
date.setMinutes(roundedMinutes);
date.setSeconds(0);
date.setMilliseconds(0);
return date;
}
/**
* Round time up to nearest 15 minutes
* @param {Date} date - Date object
* @returns {Date} - Rounded date
*/
export function roundUpTo15Min(date) {
const minutes = date.getMinutes();
const roundedMinutes = Math.ceil(minutes / 15) * 15;
date.setMinutes(roundedMinutes);
date.setSeconds(0);
date.setMilliseconds(0);
return date;
}
/**
* Format time as HH:MM
* @param {Date} date - Date object
* @returns {string} - Time in HH:MM format
*/
export function formatTime(date) {
const hours = String(date.getHours()).padStart(2, '0');
const minutes = String(date.getMinutes()).padStart(2, '0');
return `${hours}:${minutes}`;
}
/**
* Format seconds to HH:MM:SS
* @param {number} seconds - Duration in seconds
* @returns {string} - Formatted duration
*/
export function formatDuration(seconds) {
const hrs = Math.floor(seconds / 3600);
const mins = Math.floor((seconds % 3600) / 60);
const secs = seconds % 60;
return `${String(hrs).padStart(2, '0')}:${String(mins).padStart(2, '0')}:${String(secs).padStart(2, '0')}`;
}