added utility functions for date formatting and styling, refactored components to use reusable helpers

Signed-off-by: Matthias Puchstein <matthias@puchstein.bayern>
This commit is contained in:
Matthias Puchstein
2025-07-09 23:40:21 +02:00
parent 4bb7f4c979
commit bb1d778600
7 changed files with 199 additions and 90 deletions

54
src/utils/DateUtils.ts Normal file
View File

@@ -0,0 +1,54 @@
/**
* Utility functions for date formatting
*/
/**
* Formats a date with full details including weekday and month names
* @param date - The date to format
* @returns Formatted date string (e.g., "Montag, 1. Januar 2023")
*/
export const formatDateFull = (date: Date): string => {
return date.toLocaleDateString('de-DE', {
weekday: 'long',
year: 'numeric',
month: 'long',
day: 'numeric'
});
};
/**
* Formats a date in a simple format
* @param date - The date to format
* @returns Formatted date string (e.g., "01.01.2023")
*/
export const formatDateSimple = (date: Date): string => {
return date.toLocaleDateString('de-DE');
};
/**
* Formats a date with time
* @param date - The date to format
* @returns Formatted date and time string (e.g., "01.01.2023, 14:30")
*/
export const formatDateWithTime = (date: Date): string => {
return date.toLocaleDateString('de-DE', {
day: '2-digit',
month: '2-digit',
year: 'numeric',
hour: '2-digit',
minute: '2-digit',
});
};
/**
* Formats a date in a numeric format without time
* @param date - The date to format
* @returns Formatted date string (e.g., "01.01.2023")
*/
export const formatDateNumeric = (date: Date): string => {
return date.toLocaleDateString('de-DE', {
day: '2-digit',
month: '2-digit',
year: 'numeric',
});
};