21 lines
650 B
TypeScript
21 lines
650 B
TypeScript
/**
|
|
* Converts an ISO date string (YYYY-MM-DD) to German display format (DD.MM.YYYY).
|
|
* Returns an empty string for invalid or empty input.
|
|
*/
|
|
export function isoToGerman(iso: string): string {
|
|
if (!iso || !/^\d{4}-\d{2}-\d{2}$/.test(iso)) return '';
|
|
const [y, m, d] = iso.split('-');
|
|
return `${d}.${m}.${y}`;
|
|
}
|
|
|
|
/**
|
|
* Converts a German date string (DD.MM.YYYY) to ISO format (YYYY-MM-DD).
|
|
* Returns an empty string for invalid or empty input.
|
|
*/
|
|
export function germanToIso(german: string): string {
|
|
const match = german.match(/^(\d{2})\.(\d{2})\.(\d{4})$/);
|
|
if (!match) return '';
|
|
const [, d, m, y] = match;
|
|
return `${y}-${m}-${d}`;
|
|
}
|