refactor
This commit is contained in:
68
public/js/utils/dateUtils.js
Normal file
68
public/js/utils/dateUtils.js
Normal 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
|
||||
}
|
||||
Reference in New Issue
Block a user