refactor: reorganize shared/lib into per-function subfolders

This commit is contained in:
Ilia Mashkov
2026-04-24 11:41:43 +03:00
parent f3b4e1d064
commit 41edc7edf7
9 changed files with 5 additions and 5 deletions
@@ -0,0 +1,31 @@
/**
* Formats a PocketBase date string into a localized year string or "Present".
* @throws {Error} if any date is invalid or if the range is logically impossible.
*/
export function formatYearRange(start: string, end: string | null): string {
const startDate = new Date(start);
if (Number.isNaN(startDate.getTime())) {
throw new Error('Invalid start date');
}
const startYear = startDate.getFullYear();
if (end === null) {
return `${startYear} — Present`;
}
const endDate = new Date(end);
if (Number.isNaN(endDate.getTime())) {
throw new Error('Invalid end date');
}
const endYear = endDate.getFullYear();
if (startYear > endYear) {
throw new Error('Start year cannot be after end year');
}
if (startYear === endYear) {
return `${startYear}`;
}
return `${startYear}${endYear}`;
}