/** * Utility Functions * Date/Time formatting, rounding, duration formatting */ /** * Format date from YYYY-MM-DD to DD.MM.YYYY */ function formatDateDisplay(dateStr) { const [year, month, day] = dateStr.split('-'); return `${day}.${month}.${year}`; } /** * Format date from DD.MM.YYYY to YYYY-MM-DD */ function formatDateISO(dateStr) { const [day, month, year] = dateStr.split('.'); return `${year}-${month}-${day}`; } /** * Get today's date in YYYY-MM-DD format */ 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}`; } /** * Round time down to nearest 15 minutes */ 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 */ 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 */ 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 */ 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')}`; } /** * Show toast notification */ function showNotification(message, type = 'info') { const container = document.getElementById('toastContainer'); // Create toast element const toast = document.createElement('div'); toast.className = `toast toast-${type}`; // Icon based on type const icons = { success: '✓', error: '✕', info: 'ℹ' }; toast.innerHTML = ` ${icons[type] || 'ℹ'} ${message} `; container.appendChild(toast); // Auto-remove after 3 seconds setTimeout(() => { toast.classList.add('hiding'); setTimeout(() => { container.removeChild(toast); }, 300); }, 3000); } /** * Get day of week abbreviation in German */ function getDayOfWeek(date) { const days = ['So', 'Mo', 'Di', 'Mi', 'Do', 'Fr', 'Sa']; return days[date.getDay()]; } /** * Get month name in German */ function getMonthName(month) { const months = [ 'Januar', 'Februar', 'März', 'April', 'Mai', 'Juni', 'Juli', 'August', 'September', 'Oktober', 'November', 'Dezember' ]; return months[month]; }