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:
54
src/utils/DateUtils.ts
Normal file
54
src/utils/DateUtils.ts
Normal 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',
|
||||
});
|
||||
};
|
||||
Reference in New Issue
Block a user