Files
familienarchiv/frontend/src/lib/person/personLifeDates.ts
Marcel adac1b1f99 feat(person): formatLifeDateRange takes date + precision, delegates to formatDocumentDate
New formatLifeDate single-date helper carries no glyph so cards can wrap
* / † in aria-hidden spans. Missing precision falls back to YEAR.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-06-12 21:49:16 +02:00

45 lines
1.7 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { formatDocumentDate, type DatePrecision } from '$lib/shared/utils/documentDate';
/**
* Formats one life date (birth or death) at the precision the data claims,
* delegating all rendering to {@link formatDocumentDate}. Returns '' for a
* missing date. Carries no * / † glyph — components that need the glyphs wrap
* them in their own `aria-hidden` markup so screen readers only hear the date.
*
* A missing precision falls back to YEAR: pre-V76 rows only knew a year, and
* a bare year is the only safe rendering for a date without precision metadata.
*/
export function formatLifeDate(
date: string | null | undefined,
precision: DatePrecision | null | undefined,
locale?: string
): string {
if (!date) {
return '';
}
return formatDocumentDate(date, precision ?? 'YEAR', null, null, locale);
}
/**
* Formats the full life date range as plain text, e.g. for dropdown subtitles.
* Examples:
* * 14. März 1901 † 2. November 1944 (both, DAY precision)
* * 1882 (birth only, YEAR precision)
* † ca. 1944 (death only, APPROX precision)
* "" (neither)
*/
export function formatLifeDateRange(
birthDate: string | null | undefined,
birthDatePrecision: DatePrecision | null | undefined,
deathDate: string | null | undefined,
deathDatePrecision: DatePrecision | null | undefined,
locale?: string
): string {
const birth = birthDate ? `* ${formatLifeDate(birthDate, birthDatePrecision, locale)}` : null;
const death = deathDate ? `${formatLifeDate(deathDate, deathDatePrecision, locale)}` : null;
if (birth && death) {
return `${birth} ${death}`;
}
return birth ?? death ?? '';
}